3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class myClass { public $arr = ["rose"=>"red", "violet"=>"blue", "grass"=>"green"]; } $obj = new myClass; $flowers = [0=>"rose",1=>"violet"]; $closure = function( $item ){ //$arr = $this->arr; return $this->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 ahXA2
Output for 7.0.0 - 7.2.0
Roses are red, Violets are blue ...
Output for 5.4.12 - 5.6.28
Fatal error: Call to undefined method Closure::call() in /in/qCSLC on line 19
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/qCSLC on line 4
Process exited with code 255.