3v4l.org

run code in 500+ PHP versions simultaneously
<?php if (!function_exists('interface_exists')) { die('PHP version too old'); } $throwables = listThrowableClasses(); $throwablesPerParent = splitInParents($throwables); printTree($throwablesPerParent); if (count($throwablesPerParent) !== 0) { die('ERROR!!!'); } function listThrowableClasses() { $result = []; $throwableExists = interface_exists('Throwable'); if ($throwableExists) { foreach (get_declared_classes() as $cn) { $implements = class_implements($cn); if (isset($implements['Throwable'])) { $result[] = $cn; } } } if (!$throwableExists || empty($result)) { foreach (get_declared_classes() as $cn) { if ($cn === 'Exception' || is_subclass_of($cn, 'Exception')) { $result[] = $cn; } } } return $result; } function splitInParents($classes) { $result = []; foreach ($classes as $cn) { $parent = (string) get_parent_class($cn); if (isset($result[$parent])) { $result[$parent][] = $cn; } else { $result[$parent] = [$cn]; } } return $result; } function printTree(&$tree) { if (!isset($tree[''])) { die('No root classes!!!'); } printLeaves($tree, '', 0); } function printLeaves(&$tree, $parent, $level) { if (isset($tree[$parent])) { $leaves = $tree[$parent]; unset($tree[$parent]); natcasesort($leaves); $leaves = array_values($leaves); $count = count($leaves); for ($i = 0; $i < $count; ++$i) { $leaf = $leaves[$i]; echo str_repeat(' ', $level), $leaf, "\n"; printLeaves($tree, $leaf, $level + 1); } } }
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 8
Branch analysis from position: 5
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 8
2 jumps found. (Code = 43) Position 1 = 21, Position 2 = 24
Branch analysis from position: 21
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 24
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VG4TN
function name:  (null)
number of ops:  25
compiled vars:  !0 = $throwables, !1 = $throwablesPerParent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    3     0  E >   INIT_FCALL                                                   'function_exists'
          1        SEND_VAL                                                     'interface_exists'
          2        DO_ICALL                                             $2      
          3        BOOL_NOT                                             ~3      $2
          4      > JMPZ                                                         ~3, ->8
    4     5    > > INIT_FCALL                                                   'exit'
          6*       SEND_VAL                                                     'PHP+version+too+old'
          7*       DO_ICALL                                                     
    6     8    >   INIT_FCALL_BY_NAME                                           'listThrowableClasses'
          9        DO_FCALL                                          0  $5      
         10        ASSIGN                                                       !0, $5
    7    11        INIT_FCALL_BY_NAME                                           'splitInParents'
         12        SEND_VAR_EX                                                  !0
         13        DO_FCALL                                          0  $7      
         14        ASSIGN                                                       !1, $7
    8    15        INIT_FCALL_BY_NAME                                           'printTree'
         16        SEND_VAR_EX                                                  !1
         17        DO_FCALL                                          0          
    9    18        COUNT                                                ~10     !1
         19        IS_NOT_IDENTICAL                                             ~10, 0
         20      > JMPZ                                                         ~11, ->24
   10    21    > > INIT_FCALL                                                   'exit'
         22*       SEND_VAL                                                     'ERROR%21%21%21'
         23*       DO_ICALL                                                     
   72    24    > > RETURN                                                       1

Function listthrowableclasses:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 6, Position 2 = 20
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 19
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 19
Branch analysis from position: 10
2 jumps found. (Code = 43) Position 1 = 16, Position 2 = 18
Branch analysis from position: 16
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 18
Branch analysis from position: 19
2 jumps found. (Code = 47) Position 1 = 22, Position 2 = 24
Branch analysis from position: 22
2 jumps found. (Code = 43) Position 1 = 25, Position 2 = 41
Branch analysis from position: 25
2 jumps found. (Code = 77) Position 1 = 28, Position 2 = 40
Branch analysis from position: 28
2 jumps found. (Code = 78) Position 1 = 29, Position 2 = 40
Branch analysis from position: 29
2 jumps found. (Code = 47) Position 1 = 31, Position 2 = 36
Branch analysis from position: 31
2 jumps found. (Code = 43) Position 1 = 37, Position 2 = 39
Branch analysis from position: 37
1 jumps found. (Code = 42) Position 1 = 28
Branch analysis from position: 28
Branch analysis from position: 39
Branch analysis from position: 36
Branch analysis from position: 40
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 40
Branch analysis from position: 41
Branch analysis from position: 24
Branch analysis from position: 19
Branch analysis from position: 20
filename:       /in/VG4TN
function name:  listThrowableClasses
number of ops:  43
compiled vars:  !0 = $result, !1 = $throwableExists, !2 = $cn, !3 = $implements
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   15     0  E >   ASSIGN                                                       !0, <array>
   16     1        INIT_FCALL                                                   'interface_exists'
          2        SEND_VAL                                                     'Throwable'
          3        DO_ICALL                                             $5      
          4        ASSIGN                                                       !1, $5
   17     5      > JMPZ                                                         !1, ->20
   18     6    >   INIT_FCALL                                                   'get_declared_classes'
          7        DO_ICALL                                             $7      
          8      > FE_RESET_R                                           $8      $7, ->19
          9    > > FE_FETCH_R                                                   $8, !2, ->19
   19    10    >   INIT_FCALL                                                   'class_implements'
         11        SEND_VAR                                                     !2
         12        DO_ICALL                                             $9      
         13        ASSIGN                                                       !3, $9
   20    14        ISSET_ISEMPTY_DIM_OBJ                             0          !3, 'Throwable'
         15      > JMPZ                                                         ~11, ->18
   21    16    >   ASSIGN_DIM                                                   !0
         17        OP_DATA                                                      !2
   18    18    > > JMP                                                          ->9
         19    >   FE_FREE                                                      $8
   25    20    >   BOOL_NOT                                             ~13     !1
         21      > JMPNZ_EX                                             ~13     ~13, ->24
         22    >   ISSET_ISEMPTY_CV                                     ~14     !0
         23        BOOL                                                 ~13     ~14
         24    > > JMPZ                                                         ~13, ->41
   26    25    >   INIT_FCALL                                                   'get_declared_classes'
         26        DO_ICALL                                             $15     
         27      > FE_RESET_R                                           $16     $15, ->40
         28    > > FE_FETCH_R                                                   $16, !2, ->40
   27    29    >   IS_IDENTICAL                                         ~17     !2, 'Exception'
         30      > JMPNZ_EX                                             ~17     ~17, ->36
         31    >   INIT_FCALL                                                   'is_subclass_of'
         32        SEND_VAR                                                     !2
         33        SEND_VAL                                                     'Exception'
         34        DO_ICALL                                             $18     
         35        BOOL                                                 ~17     $18
         36    > > JMPZ                                                         ~17, ->39
   28    37    >   ASSIGN_DIM                                                   !0
         38        OP_DATA                                                      !2
   26    39    > > JMP                                                          ->28
         40    >   FE_FREE                                                      $16
   33    41    > > RETURN                                                       !0
   34    42*     > RETURN                                                       null

End of function listthrowableclasses

Function splitinparents:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 3, Position 2 = 19
Branch analysis from position: 3
2 jumps found. (Code = 78) Position 1 = 4, Position 2 = 19
Branch analysis from position: 4
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 15
Branch analysis from position: 11
1 jumps found. (Code = 42) Position 1 = 18
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 3
Branch analysis from position: 3
Branch analysis from position: 19
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
filename:       /in/VG4TN
function name:  splitInParents
number of ops:  22
compiled vars:  !0 = $classes, !1 = $result, !2 = $cn, !3 = $parent
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   36     0  E >   RECV                                                 !0      
   38     1        ASSIGN                                                       !1, <array>
   39     2      > FE_RESET_R                                           $5      !0, ->19
          3    > > FE_FETCH_R                                                   $5, !2, ->19
   40     4    >   INIT_FCALL                                                   'get_parent_class'
          5        SEND_VAR                                                     !2
          6        DO_ICALL                                             $6      
          7        CAST                                              6  ~7      $6
          8        ASSIGN                                                       !3, ~7
   41     9        ISSET_ISEMPTY_DIM_OBJ                             0          !1, !3
         10      > JMPZ                                                         ~9, ->15
   42    11    >   FETCH_DIM_W                                          $10     !1, !3
         12        ASSIGN_DIM                                                   $10
         13        OP_DATA                                                      !2
   41    14      > JMP                                                          ->18
   44    15    >   INIT_ARRAY                                           ~13     !2
         16        ASSIGN_DIM                                                   !1, !3
         17        OP_DATA                                                      ~13
   39    18    > > JMP                                                          ->3
         19    >   FE_FREE                                                      $5
   48    20      > RETURN                                                       !1
   49    21*     > RETURN                                                       null

End of function splitinparents

Function printtree:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 4, Position 2 = 7
Branch analysis from position: 4
1 jumps found. (Code = 61) Position 1 = -2
Branch analysis from position: 7
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VG4TN
function name:  printTree
number of ops:  13
compiled vars:  !0 = $tree
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   51     0  E >   RECV                                                 !0      
   53     1        ISSET_ISEMPTY_DIM_OBJ                             0  ~1      !0, ''
          2        BOOL_NOT                                             ~2      ~1
          3      > JMPZ                                                         ~2, ->7
   54     4    > > INIT_FCALL                                                   'exit'
          5*       SEND_VAL                                                     'No+root+classes%21%21%21'
          6*       DO_ICALL                                                     
   56     7    >   INIT_FCALL_BY_NAME                                           'printLeaves'
          8        SEND_VAR_EX                                                  !0
          9        SEND_VAL_EX                                                  ''
         10        SEND_VAL_EX                                                  0
         11        DO_FCALL                                          0          
   57    12      > RETURN                                                       null

End of function printtree

Function printleaves:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 37
Branch analysis from position: 5
1 jumps found. (Code = 42) Position 1 = 35
Branch analysis from position: 35
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 19
Branch analysis from position: 37
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 19
2 jumps found. (Code = 44) Position 1 = 37, Position 2 = 19
Branch analysis from position: 37
Branch analysis from position: 19
Branch analysis from position: 37
filename:       /in/VG4TN
function name:  printLeaves
number of ops:  38
compiled vars:  !0 = $tree, !1 = $parent, !2 = $level, !3 = $leaves, !4 = $count, !5 = $i, !6 = $leaf
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   58     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
          2        RECV                                                 !2      
   60     3        ISSET_ISEMPTY_DIM_OBJ                             0          !0, !1
          4      > JMPZ                                                         ~7, ->37
   61     5    >   FETCH_DIM_R                                          ~8      !0, !1
          6        ASSIGN                                                       !3, ~8
   62     7        UNSET_DIM                                                    !0, !1
   63     8        INIT_FCALL                                                   'natcasesort'
          9        SEND_REF                                                     !3
         10        DO_ICALL                                                     
   64    11        INIT_FCALL                                                   'array_values'
         12        SEND_VAR                                                     !3
         13        DO_ICALL                                             $11     
         14        ASSIGN                                                       !3, $11
   65    15        COUNT                                                ~13     !3
         16        ASSIGN                                                       !4, ~13
   66    17        ASSIGN                                                       !5, 0
         18      > JMP                                                          ->35
   67    19    >   FETCH_DIM_R                                          ~16     !3, !5
         20        ASSIGN                                                       !6, ~16
   68    21        INIT_FCALL                                                   'str_repeat'
         22        SEND_VAL                                                     '+++'
         23        SEND_VAR                                                     !2
         24        DO_ICALL                                             $18     
         25        ECHO                                                         $18
         26        ECHO                                                         !6
         27        ECHO                                                         '%0A'
   69    28        INIT_FCALL_BY_NAME                                           'printLeaves'
         29        SEND_VAR_EX                                                  !0
         30        SEND_VAR_EX                                                  !6
         31        ADD                                                  ~19     !2, 1
         32        SEND_VAL_EX                                                  ~19
         33        DO_FCALL                                          0          
   66    34        PRE_INC                                                      !5
         35    >   IS_SMALLER                                                   !5, !4
         36      > JMPNZ                                                        ~22, ->19
   72    37    > > RETURN                                                       null

End of function printleaves

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
168.99 ms | 2595 KiB | 23 Q