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; } $class = [ 'foo' => '', 'bar' => function (&$this) { $this['foo'] = ' World!'; }, '__construct' => function (&$this) { $this['foo'] = 'Hello'; } ]; $obj = _new($class); echo($obj['foo']); __($obj, 'bar'); echo($obj['foo']);
based on SGmGp
Output for 7.0.7 - 7.2.0
Fatal error: Cannot use $this as parameter in /in/30iDI on line 23
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Hello World!
Output for 5.6.0 - 5.6.28
Hello Catchable fatal error: Argument 2 passed to __() must be an instance of string, string given, called in /in/30iDI on line 32 and defined in /in/30iDI on line 2
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/30iDI on line 2
Process exited with code 255.