3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class Human { private $name, $age; public function __construct($name, $age) { $this->name = $name; $this->age = $age; } } $data = [["John", 23], ["Nick", 32], ["Ann", 17]]; $humans = []; foreach($data as $item) { $r = new ReflectionClass("Human"); $humans[] = $r->newInstance($item); } var_dump($humans);
based on m5N4N
Output for 7.1.0 - 7.2.0
Fatal error: Uncaught ArgumentCountError: Too few arguments to function Human::__construct(), 1 passed and exactly 2 expected in /in/COnUL:6 Stack trace: #0 [internal function]: Human->__construct(Array) #1 /in/COnUL(19): ReflectionClass->newInstance(Array) #2 {main} thrown in /in/COnUL on line 6
Process exited with code 255.
Output for 5.4.0 - 7.0.20
Warning: Missing argument 2 for Human::__construct() in /in/COnUL on line 6 Notice: Undefined variable: age in /in/COnUL on line 9 Warning: Missing argument 2 for Human::__construct() in /in/COnUL on line 6 Notice: Undefined variable: age in /in/COnUL on line 9 Warning: Missing argument 2 for Human::__construct() in /in/COnUL on line 6 Notice: Undefined variable: age in /in/COnUL on line 9 array(3) { [0]=> object(Human)#2 (2) { ["name":"Human":private]=> array(2) { [0]=> string(4) "John" [1]=> int(23) } ["age":"Human":private]=> NULL } [1]=> object(Human)#1 (2) { ["name":"Human":private]=> array(2) { [0]=> string(4) "Nick" [1]=> int(32) } ["age":"Human":private]=> NULL } [2]=> object(Human)#3 (2) { ["name":"Human":private]=> array(2) { [0]=> string(3) "Ann" [1]=> int(17) } ["age":"Human":private]=> NULL } }
Output for 5.3.19 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/COnUL on line 13
Process exited with code 255.