3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php class ExtendedSPLHeap extends \SPLHeap { protected function compare2($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(); } echo 'There are ', $citiesHeap->count(), ' cities in the heap', PHP_EOL;
Output for 5.3.0 - 5.3.24, 5.3.26 - 5.4.16
Fatal error: Class ExtendedSPLHeap contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SplHeap::compare) in rJjE4 on line 12
Process exited with code 255.
Output for 5.3.25
Fatal error: Class ExtendedSPLHeap contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (SplHeap::compare) in /in/rJjE4 on line 12
Process exited with code 255.