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 = []; if (interface_exists('Throwable')) { foreach (get_declared_classes() as $cn) { $implements = class_implements($cn); if (isset($implements['Throwable'])) { $result[] = $cn; } } } else { 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/f8Boe
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'
   70    20    > > RETURN                                                   1

Function listthrowableclasses:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 5, Position 2 = 20
Branch analysis from position: 5
2 jumps found. (Code = 77) Position 1 = 8, Position 2 = 18
Branch analysis from position: 8
2 jumps found. (Code = 78) Position 1 = 9, Position 2 = 18
Branch analysis from position: 9
2 jumps found. (Code = 43) Position 1 = 15, Position 2 = 17
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 8
Branch analysis from position: 8
Branch analysis from position: 17
Branch analysis from position: 18
1 jumps found. (Code = 42) Position 1 = 36
Branch analysis from position: 36
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 18
Branch analysis from position: 20
2 jumps found. (Code = 77) Position 1 = 23, Position 2 = 35
Branch analysis from position: 23
2 jumps found. (Code = 78) Position 1 = 24, Position 2 = 35
Branch analysis from position: 24
2 jumps found. (Code = 47) Position 1 = 26, Position 2 = 31
Branch analysis from position: 26
2 jumps found. (Code = 43) Position 1 = 32, Position 2 = 34
Branch analysis from position: 32
1 jumps found. (Code = 42) Position 1 = 23
Branch analysis from position: 23
Branch analysis from position: 34
Branch analysis from position: 31
Branch analysis from position: 35
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 35
filename:       /in/f8Boe
function name:  listThrowableClasses
number of ops:  38
compiled vars:  !0 = $result, !1 = $cn, !2 = $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                                         $4      
          4      > JMPZ                                                     $4, ->20
   17     5    >   INIT_FCALL                                               'get_declared_classes'
          6        DO_ICALL                                         $5      
          7      > FE_RESET_R                                       $6      $5, ->18
          8    > > FE_FETCH_R                                               $6, !1, ->18
   18     9    >   INIT_FCALL                                               'class_implements'
         10        SEND_VAR                                                 !1
         11        DO_ICALL                                         $7      
         12        ASSIGN                                                   !2, $7
   19    13        ISSET_ISEMPTY_DIM_OBJ                         0          !2, 'Throwable'
         14      > JMPZ                                                     ~9, ->17
   20    15    >   ASSIGN_DIM                                               !0
         16        OP_DATA                                                  !1
   17    17    > > JMP                                                      ->8
         18    >   FE_FREE                                                  $6
         19      > JMP                                                      ->36
   24    20    >   INIT_FCALL                                               'get_declared_classes'
         21        DO_ICALL                                         $11     
         22      > FE_RESET_R                                       $12     $11, ->35
         23    > > FE_FETCH_R                                               $12, !1, ->35
   25    24    >   IS_IDENTICAL                                     ~13     !1, 'Exception'
         25      > JMPNZ_EX                                         ~13     ~13, ->31
         26    >   INIT_FCALL                                               'is_subclass_of'
         27        SEND_VAR                                                 !1
         28        SEND_VAL                                                 'Exception'
         29        DO_ICALL                                         $14     
         30        BOOL                                             ~13     $14
         31    > > JMPZ                                                     ~13, ->34
   26    32    >   ASSIGN_DIM                                               !0
         33        OP_DATA                                                  !1
   24    34    > > JMP                                                      ->23
         35    >   FE_FREE                                                  $12
   31    36    > > RETURN                                                   !0
   32    37*     > 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/f8Boe
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
-------------------------------------------------------------------------------------
   34     0  E >   RECV                                             !0      
   36     1        ASSIGN                                                   !1, <array>
   37     2      > FE_RESET_R                                       $5      !0, ->19
          3    > > FE_FETCH_R                                               $5, !2, ->19
   38     4    >   INIT_FCALL                                               'get_parent_class'
          5        SEND_VAR                                                 !2
          6        DO_ICALL                                         $6      
          7        CAST                                          6  ~7      $6
          8        ASSIGN                                                   !3, ~7
   39     9        ISSET_ISEMPTY_DIM_OBJ                         0          !1, !3
         10      > JMPZ                                                     ~9, ->15
   40    11    >   FETCH_DIM_W                                      $10     !1, !3
         12        ASSIGN_DIM                                               $10
         13        OP_DATA                                                  !2
         14      > JMP                                                      ->18
   42    15    >   INIT_ARRAY                                       ~13     !2
         16        ASSIGN_DIM                                               !1, !3
         17        OP_DATA                                                  ~13
   37    18    > > JMP                                                      ->3
         19    >   FE_FREE                                                  $5
   46    20      > RETURN                                                   !1
   47    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/f8Boe
function name:  printTree
number of ops:  11
compiled vars:  !0 = $tree
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   49     0  E >   RECV                                             !0      
   51     1        ISSET_ISEMPTY_DIM_OBJ                         0  ~1      !0, ''
          2        BOOL_NOT                                         ~2      ~1
          3      > JMPZ                                                     ~2, ->5
   52     4    > > EXIT                                                     'No+root+classes%21%21%21'
   54     5    >   INIT_FCALL_BY_NAME                                       'printLeaves'
          6        SEND_VAR_EX                                              !0
          7        SEND_VAL_EX                                              ''
          8        SEND_VAL_EX                                              0
          9        DO_FCALL                                      0          
   55    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/f8Boe
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
-------------------------------------------------------------------------------------
   56     0  E >   RECV                                             !0      
          1        RECV                                             !1      
          2        RECV                                             !2      
   58     3        ISSET_ISEMPTY_DIM_OBJ                         0          !0, !1
          4      > JMPZ                                                     ~7, ->37
   59     5    >   FETCH_DIM_R                                      ~8      !0, !1
          6        ASSIGN                                                   !3, ~8
   60     7        UNSET_DIM                                                !0, !1
   61     8        INIT_FCALL                                               'natcasesort'
          9        SEND_REF                                                 !3
         10        DO_ICALL                                                 
   62    11        INIT_FCALL                                               'array_values'
         12        SEND_VAR                                                 !3
         13        DO_ICALL                                         $11     
         14        ASSIGN                                                   !3, $11
   63    15        COUNT                                            ~13     !3
         16        ASSIGN                                                   !4, ~13
   64    17        ASSIGN                                                   !5, 0
         18      > JMP                                                      ->35
   65    19    >   FETCH_DIM_R                                      ~16     !3, !5
         20        ASSIGN                                                   !6, ~16
   66    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'
   67    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          
   64    34        PRE_INC                                                  !5
         35    >   IS_SMALLER                                               !5, !4
         36      > JMPNZ                                                    ~22, ->19
   70    37    > > RETURN                                                   null

End of function printleaves

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
185.67 ms | 1408 KiB | 31 Q