3v4l.org

run code in 300+ PHP versions simultaneously
<?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 8.2.0 - 8.2.18, 8.3.0 - 8.3.7
Deprecated: Creation of dynamic property Foo::$arr is deprecated in /in/VRTtV on line 4 Warning: Bar::__construct(): Argument #1 ($foo) must be passed by reference, value given in /in/VRTtV on line 8 Warning: Bar::__construct(): Argument #2 ($arr) must be passed by reference, value given in /in/VRTtV on line 8 Deprecated: Creation of dynamic property Bar::$foo is deprecated in /in/VRTtV on line 17 Deprecated: Creation of dynamic property Bar::$arr is deprecated in /in/VRTtV on line 18 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 8.0.0 - 8.0.30, 8.1.0 - 8.1.28
Warning: Bar::__construct(): Argument #1 ($foo) must be passed by reference, value given in /in/VRTtV on line 8 Warning: Bar::__construct(): Argument #2 ($arr) must be passed by 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.1.0 - 7.1.33, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33
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.20
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.3.29, 5.4.0 - 5.4.45, 5.5.0 - 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.1.6, 5.2.0 - 5.2.4

Process exited with code 139.
Output for 5.0.0 - 5.0.5, 5.1.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.3.11, 4.4.0 - 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

preferences:
266.74 ms | 401 KiB | 399 Q