3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Proxy { private $object; private $factoryArray = []; public function __construct($object, array $factoryArray = []) { $this->object = $object; $this->factoryArray = $factoryArray; } public function __call($name, array $argumentArray) { $reflection = new ReflectionMethod($this->object, $name); $function = $reflection->getClosure($this->object)->bindTo($this, null); return call_user_func_array($function, $argumentArray); } public function __get($name) { if ($name[0] == '!') { return $this->__getFactory(substr($name, 1)); } } public function __getFactory($name) { if (isset($this->factoryArray[$name])) { return new self($this->factoryArray[$name](), $this->factoryArray); } } } class Foo { public function doStuff1() { $this->{'!Bar'}->doStuff2(); } } class Bar { public function doStuff2() { $this->{'!Qux'}->doStuff3(); } } class Qux { public function doStuff3() { var_dump(__METHOD__); } } $foo = new Proxy(new Foo, [ 'Bar' => function () { return new Bar; }, 'Qux' => function () { return new Qux; }, ]); $foo->doStuff1();
Output for git.master, git.master_jit, rfc.property-hooks
Warning: Cannot bind method Foo::doStuff1() to object of class Proxy in /in/UXibA on line 19 Fatal error: Uncaught TypeError: call_user_func_array(): Argument #1 ($callback) must be a valid callback, no array or string given in /in/UXibA:20 Stack trace: #0 /in/UXibA(80): Proxy->__call('doStuff1', Array) #1 {main} thrown in /in/UXibA on line 20
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:
42.65 ms | 401 KiB | 8 Q