3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php function struct(string $name, array $class) { $class = serialize($class); define($name, $class); } function create($class) { $class = unserialize($class); $array = []; foreach($class as $key => $value) { if(is_array($value)) $array =+ [$key => create($value)]; else $array += [$key => $value]; } return $array; } function call(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); } } } define('myClass', serialize([ 'foo' => 'Hello World!', 'bar' => function (&$this) { $this['foo'] = ' Hi!'; } ])); $obj = create(myClass); echo(call($obj, 'foo'));
based on ToT3a
Output for 7.0.20 - 7.2.0
Fatal error: Cannot use $this as parameter in /in/EW0gl on line 27
Process exited with code 255.
Output for 7.0.0 - 7.0.6
Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in /in/EW0gl:29 Stack trace: #0 /in/EW0gl(29): serialize(Array) #1 {main} thrown in /in/EW0gl on line 29
Process exited with code 255.
Output for 5.6.8 - 5.6.28
Fatal error: Uncaught exception 'Exception' with message 'Serialization of 'Closure' is not allowed' in /in/EW0gl:30 Stack trace: #0 /in/EW0gl(30): serialize(Array) #1 {main} thrown in /in/EW0gl on line 30
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/EW0gl on line 15
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/EW0gl on line 8
Process exited with code 255.