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(); $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 7.0.0 - 7.1.0
Fatal error: Uncaught RuntimeException: SplFileObject::__construct(cities.csv): failed to open stream: No such file or directory 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.
Output for hhvm-3.10.0 - 3.12.0
Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(cities.csv): failed to open stream: No such file or directory' in /in/BRIok:16 Stack trace: #0 /in/BRIok(16): SplFileObject->__construct() #1 {main}
Process exited with code 255.
Output for 5.3.0 - 5.6.28
Fatal error: Uncaught exception 'RuntimeException' with message 'SplFileObject::__construct(cities.csv): failed to open stream: No such file or directory' 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.
Output for 5.0.0 - 5.2.17
Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/BRIok on line 2 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/BRIok on line 14 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/BRIok on line 16 Warning: Unexpected character in input: '\' (ASCII=92) state=1 in /in/BRIok on line 21 Fatal error: Class 'SPLHeap' not found in /in/BRIok 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/BRIok on line 2 Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BRIok 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/BRIok on line 2 Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/BRIok 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/BRIok on line 2 Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/BRIok on line 4
Process exited with code 255.