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 \SplMaxHeap(); $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(); } $citiesHeap->top(); echo $citiesHeap->rewind(); echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL;
Output for 7.0.0 - 7.1.0
There are 2 cities in the heap FROM NORTH TO SOUTH Bristol +51.4600 -2.6000 Birmingham +52.4800 -1.9100 Fatal error: Uncaught RuntimeException: Can't peek at an empty heap in /in/oShut:48 Stack trace: #0 /in/oShut(48): SplHeap->top() #1 {main} thrown in /in/oShut on line 48
Process exited with code 255.
Output for hhvm-3.12.0
There are 2 cities in the heap FROM NORTH TO SOUTH Bristol +51.4600 -2.6000 Birmingham +52.4800 -1.9100 Fatal error: Uncaught exception 'RuntimeException' with message 'Can't peek at an empty heap' in /in/oShut:48 Stack trace: #0 /in/oShut(48): SplHeap->top() #1 {main}
Process exited with code 255.
Output for hhvm-3.10.0
There are 2 cities in the heap FROM NORTH TO SOUTH Bristol +51.4600 -2.6000 Birmingham +52.4800 -1.9100 Fatal error: Uncaught exception 'RuntimeException' with message 'Can't peek at an empty heap' in /in/oShut:-1 Stack trace: #0 /in/oShut(-1): SplHeap->top() #1 {main}
Process exited with code 255.
Output for 5.3.0 - 5.6.28
There are 2 cities in the heap FROM NORTH TO SOUTH Bristol +51.4600 -2.6000 Birmingham +52.4800 -1.9100 Fatal error: Uncaught exception 'RuntimeException' with message 'Can't peek at an empty heap' in /in/oShut:48 Stack trace: #0 /in/oShut(48): SplHeap->top() #1 {main} thrown in /in/oShut on line 48
Process exited with code 255.
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 3 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 15 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 18 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 25 Fatal error: Class 'SPLHeap' not found in /in/oShut on line 3
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 3 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oShut on line 5
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/oShut on line 3 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/oShut on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/oShut on line 3 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/oShut on line 5
Process exited with code 255.