3v4l.org

run code in 300+ PHP versions simultaneously
<?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(); $file = new \SplFileObject("cities.csv"); $file->setFlags(SplFileObject::DROP_NEW_LINE | SplFileObject::SKIP_EMPTY); while (!$file->eof()) { $cityData = $file->fgetcsv(); if ($cityData !== NULL) { $city = new \StdClass; $city->name = $cityData[0]; $city->latitude = $cityData[1]; $city->longitude = $cityData[2]; $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 git.master, git.master_jit, rfc.property-hooks
Deprecated: Return type of ExtendedSPLHeap::compare($a, $b) should either be compatible with SplHeap::compare(mixed $value1, mixed $value2): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /in/BRIok on line 4 Fatal error: Uncaught RuntimeException: SplFileObject::__construct(): open_basedir restriction in effect. File(cities.csv) is not within the allowed path(s): (/tmp:/in:/etc) in /in/BRIok:16 Stack trace: #0 /in/BRIok(16): SplFileObject->__construct('cities.csv') #1 {main} thrown in /in/BRIok on line 16
Process exited with code 255.

This tab shows result from various feature-branches currently under review by the php developers. Contact me to have additional branches featured.

Active branches

Archived branches

Once feature-branches are merged or declined, they are no longer available. Their functionality (when merged) can be viewed from the main output page


preferences:
33.32 ms | 402 KiB | 8 Q