3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php class myClass { } $obj = new myClass; $obj->color = function( $item ){ $arr = ["rose"=>"red", "violet"=>"blue", "grass"=>"green"]; return $arr[$item]; }; $flowers = [0=>"rose",1=>"violet"]; foreach ($flowers as $flower){ echo "{$flower}s are ",$obj->color($flower),"\n"; }
based on S3SH1
Output for 7.0.0 - 7.2.0
roses are Fatal error: Uncaught Error: Call to undefined method myClass::color() in /in/0f8ut:19 Stack trace: #0 {main} thrown in /in/0f8ut on line 19
Process exited with code 255.
Output for 5.4.11 - 5.6.28
roses are Fatal error: Call to undefined method myClass::color() in /in/0f8ut on line 19
Process exited with code 255.
Output for 5.3.21 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/0f8ut on line 8
Process exited with code 255.