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;
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 42) Position 1 = 31
Branch analysis from position: 31
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 11
Branch analysis from position: 35
1 jumps found. (Code = 42) Position 1 = 61
Branch analysis from position: 61
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 46
Branch analysis from position: 64
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 46
2 jumps found. (Code = 44) Position 1 = 64, Position 2 = 46
Branch analysis from position: 64
Branch analysis from position: 46
Branch analysis from position: 11
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 31
Branch analysis from position: 16
2 jumps found. (Code = 44) Position 1 = 35, Position 2 = 11
Branch analysis from position: 35
Branch analysis from position: 11
Branch analysis from position: 31
filename:       /in/BRIok
function name:  (null)
number of ops:  71
compiled vars:  !0 = $citiesHeap, !1 = $file, !2 = $cityData, !3 = $city
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   NEW                                              $4      'ExtendedSPLHeap'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $4
   16     3        NEW                                              $7      'SplFileObject'
          4        SEND_VAL_EX                                              'cities.csv'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $7
   17     7        INIT_METHOD_CALL                                         !1, 'setFlags'
          8        SEND_VAL_EX                                              5
          9        DO_FCALL                                      0          
   18    10      > JMP                                                      ->31
   19    11    >   INIT_METHOD_CALL                                         !1, 'fgetcsv'
         12        DO_FCALL                                      0  $11     
         13        ASSIGN                                                   !2, $11
   20    14        TYPE_CHECK                                  1020          !2
         15      > JMPZ                                                     ~13, ->31
   21    16    >   NEW                                              $14     'StdClass'
         17        DO_FCALL                                      0          
         18        ASSIGN                                                   !3, $14
   22    19        FETCH_DIM_R                                      ~18     !2, 0
         20        ASSIGN_OBJ                                               !3, 'name'
         21        OP_DATA                                                  ~18
   23    22        FETCH_DIM_R                                      ~20     !2, 1
         23        ASSIGN_OBJ                                               !3, 'latitude'
         24        OP_DATA                                                  ~20
   24    25        FETCH_DIM_R                                      ~22     !2, 2
         26        ASSIGN_OBJ                                               !3, 'longitude'
         27        OP_DATA                                                  ~22
   26    28        INIT_METHOD_CALL                                         !0, 'insert'
         29        SEND_VAR_EX                                              !3
         30        DO_FCALL                                      0          
   18    31    >   INIT_METHOD_CALL                                         !1, 'eof'
         32        DO_FCALL                                      0  $24     
         33        BOOL_NOT                                         ~25     $24
         34      > JMPNZ                                                    ~25, ->11
   30    35    >   ECHO                                                     'There+are+'
         36        INIT_METHOD_CALL                                         !0, 'count'
         37        DO_FCALL                                      0  $26     
         38        ECHO                                                     $26
         39        ECHO                                                     '+cities+in+the+heap'
         40        ECHO                                                     '%0A'
   32    41        ECHO                                                     'FROM+NORTH+TO+SOUTH'
         42        ECHO                                                     '%0A'
   33    43        INIT_METHOD_CALL                                         !0, 'top'
         44        DO_FCALL                                      0          
   34    45      > JMP                                                      ->61
   35    46    >   INIT_METHOD_CALL                                         !0, 'current'
         47        DO_FCALL                                      0  $28     
         48        ASSIGN                                                   !3, $28
   37    49        INIT_FCALL                                               'sprintf'
   38    50        SEND_VAL                                                 '%25-20s+%25%2B3.4f++%25%2B3.4f%0A'
   39    51        FETCH_OBJ_R                                      ~30     !3, 'name'
         52        SEND_VAL                                                 ~30
   40    53        FETCH_OBJ_R                                      ~31     !3, 'latitude'
         54        SEND_VAL                                                 ~31
   41    55        FETCH_OBJ_R                                      ~32     !3, 'longitude'
         56        SEND_VAL                                                 ~32
         57        DO_ICALL                                         $33     
         58        ECHO                                                     $33
   44    59        INIT_METHOD_CALL                                         !0, 'next'
         60        DO_FCALL                                      0          
   34    61    >   INIT_METHOD_CALL                                         !0, 'valid'
         62        DO_FCALL                                      0  $35     
         63      > JMPNZ                                                    $35, ->46
   47    64    >   ECHO                                                     'There+are+'
         65        INIT_METHOD_CALL                                         !0, 'count'
         66        DO_FCALL                                      0  $36     
         67        ECHO                                                     $36
         68        ECHO                                                     '+cities+in+the+heap'
         69        ECHO                                                     '%0A'
         70      > RETURN                                                   1

Class ExtendedSPLHeap:
Function compare:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 7
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 13
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/BRIok
function name:  compare
number of ops:  16
compiled vars:  !0 = $a, !1 = $b
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E >   RECV                                             !0      
          1        RECV                                             !1      
    5     2        FETCH_OBJ_R                                      ~2      !0, 'latitude'
          3        FETCH_OBJ_R                                      ~3      !1, 'latitude'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
    6     6    > > RETURN                                                   0
    8     7    >   FETCH_OBJ_R                                      ~5      !0, 'latitude'
          8        FETCH_OBJ_R                                      ~6      !1, 'latitude'
          9        IS_SMALLER                                               ~5, ~6
         10      > JMPZ                                                     ~7, ->13
         11    >   QM_ASSIGN                                        ~8      -1
         12      > JMP                                                      ->14
         13    >   QM_ASSIGN                                        ~8      1
         14    > > RETURN                                                   ~8
    9    15*     > RETURN                                                   null

End of function compare

End of class ExtendedSPLHeap.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
144.09 ms | 1404 KiB | 15 Q