3v4l.org

run code in 300+ PHP versions simultaneously
<?php class App { public static $classes = array(); public function register($name, Callable $generator) { $this::$classes[$name] = $generator; } public function make($name) { if (!isset($this::$classes[$name])) { throw new Exception('Invalid class name'); } $classes &= $this::$classes; return $classes[$name](); } } $app = new App; // Internal declaration class Foo { public static function bar() { return 'static'; } } $app->register('foo', function() { return new Foo; }); // Internal Usage class SomeController { public function view() { $app = new App; 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 git.master, git.master_jit, rfc.property-hooks
Warning: Undefined variable $classes in /in/btTCs on line 16 Fatal error: Uncaught TypeError: Unsupported operand types: null & array in /in/btTCs:16 Stack trace: #0 /in/btTCs(44): App->make('foo') #1 /in/btTCs(65): SomeController->view() #2 {main} thrown in /in/btTCs on line 16
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
40.18 ms | 401 KiB | 8 Q