3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function struct(string $name, array $class) { $class = json_encode($class); define($name, $class); } function create($class) { $object = (array) json_decode($class); return $object; } function call(array &$class, string $member, ...$args) { if(!isset($class[$member])) exit($member.' is not a member of the class.'); else { if(!isset($args[0])) $class[$member]($class); else call_user_func([$class, $member], $class, $args); } } $obj = [ 'foo' => function (&$this) { echo('Hello World!'); } ]; call($obj, 'foo');
based on vcQ4U
Output for 7.0.7 - 7.2.0
Fatal error: Cannot use $this as parameter in /in/Wsvkl on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Hello World!
Output for 5.6.0 - 5.6.28
Catchable fatal error: Argument 2 passed to call() must be an instance of string, string given, called in /in/Wsvkl on line 23 and defined in /in/Wsvkl on line 10
Process exited with code 255.
Output for 5.5.0 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/Wsvkl on line 10
Process exited with code 255.