3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class Foo { function __construct (&$arr) { $this->arr = &$arr; } function createInstance () { $reflectionClass = new ReflectionClass("Bar"); return $reflectionClass->newInstanceArgs(array($this, $this->arr)); } function mod($key, $val) { $this->arr[$key] = $val; } } class Bar { function __construct (&$foo, &$arr) { $this->foo = &$foo; $this->arr = &$arr; } function mod($key, $val) { $this->arr[$key] = $val; } } $arr = array(); $foo = new Foo($arr); $arr["x"] = 1; $foo->mod("y", 2); $bar = $foo->createInstance(); $bar->mod("z", 3); var_dump($arr,$foo,$bar);
Output for 7.1.0
Warning: Parameter 1 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 Warning: Parameter 2 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 array(2) { ["x"]=> int(1) ["y"]=> int(2) } object(Foo)#1 (1) { ["arr"]=> &array(2) { ["x"]=> int(1) ["y"]=> int(2) } } object(Bar)#3 (2) { ["foo"]=> object(Foo)#1 (1) { ["arr"]=> &array(2) { ["x"]=> int(1) ["y"]=> int(2) } } ["arr"]=> array(3) { ["x"]=> int(1) ["y"]=> int(2) ["z"]=> int(3) } }
Output for 7.0.0 - 7.0.14
Warning: Parameter 1 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 Warning: ReflectionClass::newInstanceArgs(): Invocation of Bar's constructor failed in /in/VRTtV on line 8 Fatal error: Uncaught Error: Call to a member function mod() on null in /in/VRTtV:35 Stack trace: #0 {main} thrown in /in/VRTtV on line 35
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Warning: Parameter 1 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 Warning: ReflectionClass::newInstanceArgs(): Invocation of Bar's constructor failed in /in/VRTtV on line 8 Fatal error: Call to a member function mod() on null in /in/VRTtV on line 35
Process exited with code 255.
Output for 5.3.3 - 5.5.38
Warning: Parameter 1 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 Warning: ReflectionClass::newInstanceArgs(): Invocation of Bar's constructor failed in /in/VRTtV on line 8 Fatal error: Call to a member function mod() on a non-object in /in/VRTtV on line 35
Process exited with code 255.
Output for 5.3.0 - 5.3.2
Warning: Parameter 1 to Bar::__construct() expected to be a reference, value given in /in/VRTtV on line 8 Warning: Invocation of Bar's constructor failed in /in/VRTtV on line 8 Fatal error: Call to a member function mod() on a non-object in /in/VRTtV on line 35
Process exited with code 255.
Output for 5.2.5 - 5.2.17
Warning: Invocation of Bar's constructor failed in /in/VRTtV on line 8 Fatal error: Call to a member function mod() on a non-object in /in/VRTtV on line 35
Process exited with code 255.
Output for 5.1.3 - 5.2.4

Process exited with code 139.
Output for 5.0.0 - 5.1.2
Fatal error: Call to undefined method ReflectionClass::newInstanceArgs() in /in/VRTtV on line 8
Process exited with code 255.
Output for 4.3.2 - 4.4.9
Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/VRTtV on line 7
Process exited with code 255.
Output for 4.3.0 - 4.3.1
Fatal error: Cannot instantiate non-existent class: reflectionclass in /in/VRTtV on line 7