3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class myClass {} $obj = new myClass; $flowers = [0=>"rose",1=>"violet"]; $closure = function( $item ){ $arr = ["rose"=>"red", "violet"=>"blue", "grass"=>"green"]; return $arr[$item]; }; foreach ($flowers as $key => $flower){ $color = $closure->call($obj,$flower); echo ucfirst("{$flower}s are $color"); echo ($key == 0)? ",\n" : " ...\n"; }
based on Kcgdn
Output for 7.0.0 - 7.2.0
Roses are red, Violets are blue ...
Output for 5.4.11 - 5.6.28
Fatal error: Call to undefined method Closure::call() in /in/eBQ1h on line 18
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/eBQ1h on line 7
Process exited with code 255.