3v4l.org

run code in 300+ PHP versions simultaneously
<?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])) call_user_func([$class, $member], $class); else call_user_func([$class, $member], $class, $args); } } $obj = [ 'foo' => function (&$this) { echo('Hello World!'); } ]; call($obj, 'foo');
Output for 7.0.7 - 7.0.33, 7.1.0 - 7.1.25, 7.2.0 - 7.2.33, 7.3.0 - 7.3.33, 7.4.0 - 7.4.33, 8.0.0 - 8.0.30, 8.1.0 - 8.1.28, 8.2.0 - 8.2.19, 8.3.0 - 8.3.7
Fatal error: Cannot use $this as parameter in /in/vcQ4U on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object in /in/vcQ4U on line 13
Output for 5.6.0 - 5.6.38
Catchable fatal error: Argument 2 passed to call() must be an instance of string, string given, called in /in/vcQ4U on line 23 and defined in /in/vcQ4U 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/vcQ4U on line 10
Process exited with code 255.

preferences:
195.28 ms | 401 KiB | 295 Q