3v4l.org

run code in 300+ PHP versions simultaneously
<?php class myClass { public function __construct(){ echo __CLASS__; } } $obj = new myClass; $flower = "violet"; $obj->clr = "bluish"; $obj->color = function()use($flower){ $arr = ["rose"=>"red", "violet"=>"blue", "grass"=>"green"]; return $arr[$flower]; }; echo "...{$flower}s are ",$obj->clr,"\n"; if (phpversion() >= "7.0.0"){ echo "...{$flower}s are ",($obj->color)(); }
Output for 7.0.0 - 7.0.20, 7.1.0 - 7.1.20, 7.2.0 - 7.2.11
myClass...violets are bluish ...violets are blue
Output for 5.5.24 - 5.5.35, 5.6.8 - 5.6.28
Parse error: syntax error, unexpected '(', expecting ',' or ';' in /in/Ytl8F on line 22
Process exited with code 255.

preferences:
73.14 ms | 402 KiB | 50 Q