3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ExtendedSPLHeap extends \SPLHeap { protected function compare($a, $b) { if ($a->latitude == $b->latitude) { return 0; } return ($a->latitude < $b->latitude) ? -1 : 1; } } $citiesHeap = new \ExtendedSPLHeap(); $city = new \StdClass; $city->name = "Birmingham"; $city->latitude = 52.4800; $city->longitude = -1.9100; $citiesHeap->insert($city); $city = new \StdClass; $city->name = "Bristol"; $city->latitude = 51.4600; $city->longitude = -2.6000; $citiesHeap->insert($city); echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL; echo 'FROM NORTH TO SOUTH', PHP_EOL; $citiesHeap->top(); while ($citiesHeap->valid()) { $city = $citiesHeap->current(); echo sprintf( "%-20s %+3.4f %+3.4f" . PHP_EOL, $city->name, $city->latitude, $city->longitude ); $citiesHeap->next(); } echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL;
Output for 5.3.0 - 5.6.28, hhvm-3.10.0 - 3.12.0, 7.0.0 - 7.1.0
There are 2 cities in the heap FROM NORTH TO SOUTH Birmingham +52.4800 -1.9100 Bristol +51.4600 -2.6000 There are 0 cities in the heap
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 17 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 24 Fatal error: Class 'SPLHeap' not found in /in/NHcLU on line 2
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 2 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NHcLU on line 4
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 2 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/NHcLU on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/NHcLU on line 2 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/NHcLU on line 4
Process exited with code 255.