3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function call(array &$class, string $member, ...$args) { if(!isset($args[1])) { if(!isset($class[$member])) exit($member.' is not a member of the class.'); else { if(!is_callable($class[$member])) return $class[$member]; else { $class[$member]($class); } } } else { } } $myClass = [ 'foo' => 'Hello World', 'bar' => function (&$this) { $this['foo'] = 'Hi!'; } ]; echo(call($myClass, 'foo')); call($myClass, 'bar'); echo(call($myClass, 'foo'));
based on n4Qjj
Output for 7.0.20 - 7.2.0
Fatal error: Cannot use $this as parameter in /in/ZDuqB on line 19
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Hello WorldHi!
Output for 5.6.8 - 5.6.28
Catchable fatal error: Argument 2 passed to call() must be an instance of string, string given, called in /in/ZDuqB on line 23 and defined in /in/ZDuqB on line 2
Process exited with code 255.
Output for 5.4.11 - 5.5.35
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/ZDuqB on line 2
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '.', expecting '&' or T_VARIABLE in /in/ZDuqB on line 2
Process exited with code 255.