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); //if(function_exists($object['__construct']())) $object['__construct']($object); 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])) call_user_func($class[$member]($class)); else call_user_func($class[$member]($class, $args)); } } struct('myStruct', [ 'foo' => 'Hello World!', 'bar' => function (array &$this) { echo(' Hi!'); } ]); $obj = create(myStruct); call($obj, 'bar');
based on smZpd
Output for 7.0.7 - 7.2.0
Fatal error: Cannot use $this as parameter in /in/KfVQm on line 21
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Fatal error: Uncaught Error: Function name must be a string in /in/KfVQm:14 Stack trace: #0 /in/KfVQm(26): call(Array, 'bar') #1 {main} thrown in /in/KfVQm on line 14
Process exited with code 255.
Output for 5.6.0 - 5.6.28
Catchable fatal error: Argument 1 passed to struct() must be an instance of string, string given, called in /in/KfVQm on line 24 and defined in /in/KfVQm on line 2
Process exited with code 255.
Output for 5.5.0 - 5.5.37
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/KfVQm on line 11
Process exited with code 255.