3v4l.org

run code in 300+ PHP versions simultaneously
<?php abstract class AHeap extends SplHeap { public function __construct($i) { foreach ($i as $obj) { $this->insert($obj); } } } class KeySort extends AHeap { public function compare($val1, $val2) { if ($val1->key == $val2->key) return 0; if ($val1->key < $val2->key){ return -1; } else { return 1; } } } class ValueSort extends AHeap { public function compare($val1, $val2) { if ($val1->value == $val2->value) return 0; if ($val1->value < $val2->value){ return -1; } else { return 1; } } } $array = array( (object) array('key' => 0, 'value' => 'z'), (object) array('key' => 1, 'value' => 'a'), (object) array('key' => 2, 'value' => 'y'), (object) array('key' => 3, 'value' => 'b'), ); $heap = new KeySort($array); foreach ($heap as $val) { echo $val->key . ' - ' . $val->value . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 22
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 22
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 22
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 22
filename:       /in/9vYqR
function name:  (null)
number of ops:  24
compiled vars:  !0 = $array, !1 = $heap, !2 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   CAST                                          8  ~3      <array>
          1        INIT_ARRAY                                       ~4      ~3
   47     2        CAST                                          8  ~5      <array>
          3        ADD_ARRAY_ELEMENT                                ~4      ~5
   48     4        CAST                                          8  ~6      <array>
          5        ADD_ARRAY_ELEMENT                                ~4      ~6
   49     6        CAST                                          8  ~7      <array>
          7        ADD_ARRAY_ELEMENT                                ~4      ~7
   45     8        ASSIGN                                                   !0, ~4
   52     9        NEW                                              $9      'KeySort'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $9
   54    13      > FE_RESET_R                                       $12     !1, ->22
         14    > > FE_FETCH_R                                               $12, !2, ->22
   55    15    >   FETCH_OBJ_R                                      ~13     !2, 'key'
         16        CONCAT                                           ~14     ~13, '+-+'
         17        FETCH_OBJ_R                                      ~15     !2, 'value'
         18        CONCAT                                           ~16     ~14, ~15
         19        CONCAT                                           ~17     ~16, '%0A'
         20        ECHO                                                     ~17
   54    21      > JMP                                                      ->14
         22    >   FE_FREE                                                  $12
   56    23      > RETURN                                                   1

Class AHeap:
Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/9vYqR
function name:  __construct
number of ops:  9
compiled vars:  !0 = $i, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
    8     3    >   INIT_METHOD_CALL                                         'insert'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
    7     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   10     8      > RETURN                                                   null

End of function __construct

End of class AHeap.

Class KeySort:
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 = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9vYqR
function name:  compare
number of ops:  15
compiled vars:  !0 = $val1, !1 = $val2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   15     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   17     2        FETCH_OBJ_R                                      ~2      !0, 'key'
          3        FETCH_OBJ_R                                      ~3      !1, 'key'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   18     6    > > RETURN                                                   0
   20     7    >   FETCH_OBJ_R                                      ~5      !0, 'key'
          8        FETCH_OBJ_R                                      ~6      !1, 'key'
          9        IS_SMALLER                                               ~5, ~6
         10      > JMPZ                                                     ~7, ->13
   21    11    > > RETURN                                                   -1
         12*       JMP                                                      ->14
   24    13    > > RETURN                                                   1
   26    14*     > RETURN                                                   null

End of function compare

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/9vYqR
function name:  __construct
number of ops:  9
compiled vars:  !0 = $i, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
    8     3    >   INIT_METHOD_CALL                                         'insert'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
    7     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   10     8      > RETURN                                                   null

End of function __construct

End of class KeySort.

Class ValueSort:
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 = 62) Position 1 = -2
Branch analysis from position: 13
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/9vYqR
function name:  compare
number of ops:  15
compiled vars:  !0 = $val1, !1 = $val2
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   RECV                                             !0      
          1        RECV                                             !1      
   33     2        FETCH_OBJ_R                                      ~2      !0, 'value'
          3        FETCH_OBJ_R                                      ~3      !1, 'value'
          4        IS_EQUAL                                                 ~2, ~3
          5      > JMPZ                                                     ~4, ->7
   34     6    > > RETURN                                                   0
   36     7    >   FETCH_OBJ_R                                      ~5      !0, 'value'
          8        FETCH_OBJ_R                                      ~6      !1, 'value'
          9        IS_SMALLER                                               ~5, ~6
         10      > JMPZ                                                     ~7, ->13
   37    11    > > RETURN                                                   -1
         12*       JMP                                                      ->14
   40    13    > > RETURN                                                   1
   42    14*     > RETURN                                                   null

End of function compare

Function __construct:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 2, Position 2 = 7
Branch analysis from position: 2
2 jumps found. (Code = 78) Position 1 = 3, Position 2 = 7
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 2
Branch analysis from position: 2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 7
filename:       /in/9vYqR
function name:  __construct
number of ops:  9
compiled vars:  !0 = $i, !1 = $obj
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    5     0  E >   RECV                                             !0      
    7     1      > FE_RESET_R                                       $2      !0, ->7
          2    > > FE_FETCH_R                                               $2, !1, ->7
    8     3    >   INIT_METHOD_CALL                                         'insert'
          4        SEND_VAR_EX                                              !1
          5        DO_FCALL                                      0          
    7     6      > JMP                                                      ->2
          7    >   FE_FREE                                                  $2
   10     8      > RETURN                                                   null

End of function __construct

End of class ValueSort.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.4 ms | 1403 KiB | 13 Q