3v4l.org

run code in 300+ 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 = 6
Branch analysis from position: 5
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 6
2 jumps found. (Code = 43) Position 1 = 19, Position 2 = 20
Branch analysis from position: 19
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 20
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VG4TN
function name:  (null)
number of ops:  21
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, ->6
    4     5    > > EXIT                                                     'PHP+version+too+old'
    6     6    >   INIT_FCALL_BY_NAME                                       'listThrowableClasses'
          7        DO_FCALL                                      0  $4      
          8        ASSIGN                                                   !0, $4
    7     9        INIT_FCALL_BY_NAME                                       'splitInParents'
         10        SEND_VAR_EX                                              !0
         11        DO_FCALL                                      0  $6      
         12        ASSIGN                                                   !1, $6
    8    13        INIT_FCALL_BY_NAME                                       'printTree'
         14        SEND_VAR_EX                                              !1
         15        DO_FCALL                                      0          
    9    16        COUNT                                            ~9      !1
         17        IS_NOT_IDENTICAL                                         ~9, 0
         18      > JMPZ                                                     ~10, ->20
   10    19    > > EXIT                                                     'ERROR%21%21%21'
   72    20    > > 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
         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 = 5
Branch analysis from position: 4
1 jumps found. (Code = 79) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/VG4TN
function name:  printTree
number of ops:  11
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, ->5
   54     4    > > EXIT                                                     'No+root+classes%21%21%21'
   56     5    >   INIT_FCALL_BY_NAME                                       'printLeaves'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              ''
          8        SEND_VAL_EX                                              0
          9        DO_FCALL                                      0          
   57    10      > 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.0.0


preferences:
171.24 ms | 1404 KiB | 31 Q