3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class myClass { public function __construct(){ echo __CLASS__,"\n"; } } $obj = new myClass; var_dump($obj); $flower = "violet"; $obj->color = function()use($flower){ $arr = ["rose"=>"red", "violet"=>"blue", "grass"=>"green"]; return $arr[$flower]; }; var_dump($obj); echo "...{$flower}s are ",($obj->color)();
based on Ac0LN
Output for 7.0.0 - 7.2.0
myClass object(myClass)#1 (0) { } object(myClass)#1 (1) { ["color"]=> object(Closure)#2 (1) { ["static"]=> array(1) { ["flower"]=> string(6) "violet" } } } ...violets are blue
Output for 5.4.11 - 5.6.28
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /in/8G4Ja on line 20
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/8G4Ja on line 13
Process exited with code 255.