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 ){ 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"; }
Output for 7.1.0 - 7.2.0
Notice: Undefined variable: arr in /in/TiC7X on line 14 Notice: Undefined property: myClass::$ in /in/TiC7X on line 14 Roses are , Notice: Undefined variable: arr in /in/TiC7X on line 14 Notice: Undefined property: myClass::$ in /in/TiC7X on line 14 Violets are ...
Output for 7.0.0 - 7.0.20
Notice: Undefined variable: arr in /in/TiC7X on line 14 Fatal error: Uncaught Error: Cannot access empty property in /in/TiC7X:14 Stack trace: #0 [internal function]: myClass->{closure}('rose') #1 /in/TiC7X(18): Closure->call(Object(myClass), 'rose') #2 {main} thrown in /in/TiC7X on line 14
Process exited with code 255.
Output for 5.4.12 - 5.6.28
Fatal error: Call to undefined method Closure::call() in /in/TiC7X on line 18
Process exited with code 255.
Output for 5.3.22 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/TiC7X on line 4
Process exited with code 255.