3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function __(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); else $class[$member]($class, $args); } } } function _new(array $class, ...$args) { $obj = $class; if(isset($class['__construct'])) { if(isset($args[0])) $obj['__construct']($obj, $args); else $obj['__construct']($obj); } return $obj; } $obj = [ 'foo' => '', 'bar' => function (&$this) { $this['foo'] = ' World!'; }, '__construct' => function (&$this) { $this['foo'] = 'Hello'; } ]; echo($obj['foo']); __($obj, 'bar'); echo($obj['foo']);
based on tMujt
Output for 7.0.7 - 7.3.1
Fatal error: Cannot use $this as parameter in /in/SGmGp on line 23
Process exited with code 255.
Output for 7.0.0 - 7.0.6
World!
Output for 5.6.0 - 5.6.38
Catchable fatal error: Argument 2 passed to __() must be an instance of string, string given, called in /in/SGmGp on line 31 and defined in /in/SGmGp on line 2
Process exited with code 255.
Output for 5.4.11 - 5.5.38
Parse error: syntax error, unexpected '.', expecting '&' or variable (T_VARIABLE) in /in/SGmGp 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/SGmGp on line 2
Process exited with code 255.