3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php $obj1 = [['main' => 10, 'fallback' => 5]]; $obj2 = [['main' => null, 'fallback' => 5]]; $obj3 = [['main' => null, 'fallback' => null]]; $obj4 = [[]]; $obj5 = [['fallback' => 5]]; $obj6 = [['main' => 10]]; function doStuff($obj) { return $obj[0]['main'] ?? $obj[0]['fallback'] ?? 0; } var_dump(doStuff($obj1)); var_dump(doStuff($obj2)); var_dump(doStuff($obj3)); var_dump(doStuff($obj4)); var_dump(doStuff($obj5)); var_dump(doStuff($obj6));
Output for 7.0.0 - 7.2.0
int(10) int(5) int(0) int(0) int(5) int(10)
Output for 5.4.0 - 5.6.28
Parse error: syntax error, unexpected '?' in /in/l49oT on line 11
Process exited with code 255.
Output for 4.4.2 - 4.4.9, 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/l49oT on line 3
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1, 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/l49oT on line 3
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/l49oT on line 3
Process exited with code 255.