3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function \new(array $class) { $array = []; foreach($class as $key => $value) { if(is_array($value)) $array =+ [$key => new($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 = new($myClass); echo(call($obj, 'foo')); call($obj, 'bar'); echo(call($obj, 'foo'));
based on TjAcE
Output for 5.4.11 - 5.4.45, 7.0.0 - 7.0.1
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting identifier (T_STRING) or '(' in /in/mDCIf on line 2
Process exited with code 255.
Output for 5.5.24 - 5.6.16
Parse error: syntax error, unexpected '\' (T_NS_SEPARATOR), expecting '(' in /in/mDCIf on line 2
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected T_NS_SEPARATOR, expecting T_STRING or '(' in /in/mDCIf on line 2
Process exited with code 255.