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' => 0, 'value' => 'a'), (object) array('key' => 2, 'value' => 'y'), (object) array('key' => 3, 'value' => 'b'), ); $heap = new KeySort($array); $heap2 = new ValueSort($heap); foreach ($heap2 as $val) { echo $val->key . ' - ' . $val->value . PHP_EOL; }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 18, Position 2 = 26
Branch analysis from position: 18
2 jumps found. (Code = 78) Position 1 = 19, Position 2 = 26
Branch analysis from position: 19
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
Branch analysis from position: 26
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 26
filename:       /in/3AqnE
function name:  (null)
number of ops:  28
compiled vars:  !0 = $array, !1 = $heap, !2 = $heap2, !3 = $val
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   46     0  E >   CAST                                          8  ~4      <array>
          1        INIT_ARRAY                                       ~5      ~4
   47     2        CAST                                          8  ~6      <array>
          3        ADD_ARRAY_ELEMENT                                ~5      ~6
   48     4        CAST                                          8  ~7      <array>
          5        ADD_ARRAY_ELEMENT                                ~5      ~7
   49     6        CAST                                          8  ~8      <array>
          7        ADD_ARRAY_ELEMENT                                ~5      ~8
   45     8        ASSIGN                                                   !0, ~5
   52     9        NEW                                              $10     'KeySort'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0          
         12        ASSIGN                                                   !1, $10
   53    13        NEW                                              $13     'ValueSort'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
         16        ASSIGN                                                   !2, $13
   55    17      > FE_RESET_R                                       $16     !2, ->26
         18    > > FE_FETCH_R                                               $16, !3, ->26
   56    19    >   FETCH_OBJ_R                                      ~17     !3, 'key'
         20        CONCAT                                           ~18     ~17, '+-+'
         21        FETCH_OBJ_R                                      ~19     !3, 'value'
         22        CONCAT                                           ~20     ~18, ~19
         23        CONCAT                                           ~21     ~20, '%0A'
         24        ECHO                                                     ~21
   55    25      > JMP                                                      ->18
         26    >   FE_FREE                                                  $16
   57    27      > 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/3AqnE
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/3AqnE
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                                               ~6, ~5
         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/3AqnE
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/3AqnE
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/3AqnE
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:
172.94 ms | 1403 KiB | 13 Q