3v4l.org

run code in 300+ PHP versions simultaneously
<?php function create(array $class) { $array = []; foreach($class as $key => $value) { if(is_array($value)) $array =+ [$key => create($value)]; else $array += [$key => $value]; } return $array; } function call(array &$class, string $member, ...$args) { if(!isset($class[$member])) exit($member.' is not a member of the class.'); else { if(!is_callable($class[$member])) return $class[$member]; else { if(!isset($args[0])) $class[$member]($class); } } } const myClass = [ 'foo' => 'Hello World', 'bar' => function (&$this) { $this['foo'] = 'Hi!'; }]; $obj = create(myClass); echo(call($obj, 'foo')); call($obj, 'bar'); echo(call($obj, 'foo'));
Output for 7.0.0 - 7.0.1
Fatal error: Constant expression contains invalid operations in /in/4CXiT on line 24
Process exited with code 255.
Output for 5.6.8 - 5.6.16
Parse error: syntax error, unexpected 'function' (T_FUNCTION) in /in/4CXiT on line 22
Process exited with code 255.
Output for 5.5.24 - 5.5.30
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/4CXiT on line 10
Process exited with code 255.

preferences:
172.36 ms | 1395 KiB | 25 Q