3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public static $classes = array(); function static register($name, Callable $generator) { $classes[$name] = $generator; } function static make($name) { if (!isset($classes[$name])) { throw new Exception('Invalid class name'); } return ($classes[$name])(); } } // Internal declaration class Foo { public static function bar() { return 'static'; } } App::register('foo', function() { return new Foo; }); // Internal Usage class SomeController { public function view() { echo App::make('foo')->bar(); } } // Some extending application class MyFoo extends Foo { public static function bar() { return 'can\'t make internal methods use this.'; } } App::register('foo', function() { return new MyFoo; }); $c = new SomeController; $c->view();
Output for 5.4.0 - 5.4.27
Parse error: syntax error, unexpected 'static' (T_STATIC), expecting identifier (T_STRING) in /in/EHjBn on line 7
Process exited with code 255.
Output for 5.3.0 - 5.3.28
Parse error: syntax error, unexpected T_STATIC, expecting T_STRING in /in/EHjBn on line 7
Process exited with code 255.

preferences:
183.58 ms | 1386 KiB | 64 Q