3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait Blah { function getOne() { return 1;} } abstract class AbstractTest { use Blah; } class Test extends AbstractTest {} function hier($class) { $traits = class_uses($class) ?: []; $parents = class_parents($class) ?: []; foreach ($parents as $parent) { array_merge($traits, hier($parent)); } return $traits; } $t = new Test; echo $t->getOne() . "\n"; var_dump(class_parents(Test::class)); var_dump(hier(Test::class));
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H2g0M
function name:  (null)
number of ops:  22
compiled vars:  !0 = $t
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   DECLARE_CLASS                                            'abstracttest'
   11     1        DECLARE_CLASS                                            'test', 'abstracttest'
   25     2        NEW                                              $1      'Test'
          3        DO_FCALL                                      0          
          4        ASSIGN                                                   !0, $1
   28     5        INIT_METHOD_CALL                                         !0, 'getOne'
          6        DO_FCALL                                      0  $4      
          7        CONCAT                                           ~5      $4, '%0A'
          8        ECHO                                                     ~5
   29     9        INIT_FCALL                                               'var_dump'
         10        INIT_FCALL                                               'class_parents'
         11        SEND_VAL                                                 'Test'
         12        DO_ICALL                                         $6      
         13        SEND_VAR                                                 $6
         14        DO_ICALL                                                 
   30    15        INIT_FCALL                                               'var_dump'
         16        INIT_FCALL                                               'hier'
         17        SEND_VAL                                                 'Test'
         18        DO_FCALL                                      0  $8      
         19        SEND_VAR                                                 $8
         20        DO_ICALL                                                 
         21      > RETURN                                                   1

Function hier:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 14, Position 2 = 23
Branch analysis from position: 14
2 jumps found. (Code = 78) Position 1 = 15, Position 2 = 23
Branch analysis from position: 15
1 jumps found. (Code = 42) Position 1 = 14
Branch analysis from position: 14
Branch analysis from position: 23
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 23
filename:       /in/H2g0M
function name:  hier
number of ops:  26
compiled vars:  !0 = $class, !1 = $traits, !2 = $parents, !3 = $parent
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   RECV                                             !0      
   14     1        INIT_FCALL                                               'class_uses'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $4      
          4        JMP_SET                                          ~5      $4, ->6
          5        QM_ASSIGN                                        ~5      <array>
          6        ASSIGN                                                   !1, ~5
   15     7        INIT_FCALL                                               'class_parents'
          8        SEND_VAR                                                 !0
          9        DO_ICALL                                         $7      
         10        JMP_SET                                          ~8      $7, ->12
         11        QM_ASSIGN                                        ~8      <array>
         12        ASSIGN                                                   !2, ~8
   17    13      > FE_RESET_R                                       $10     !2, ->23
         14    > > FE_FETCH_R                                               $10, !3, ->23
   18    15    >   INIT_FCALL                                               'array_merge'
         16        SEND_VAR                                                 !1
         17        INIT_FCALL_BY_NAME                                       'hier'
         18        SEND_VAR_EX                                              !3
         19        DO_FCALL                                      0  $11     
         20        SEND_VAR                                                 $11
         21        DO_ICALL                                                 
   17    22      > JMP                                                      ->14
         23    >   FE_FREE                                                  $10
   21    24      > RETURN                                                   !1
   22    25*     > RETURN                                                   null

End of function hier

Class Blah:
Function getone:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/H2g0M
function name:  getOne
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    4     0  E > > RETURN                                                   1
          1*     > RETURN                                                   null

End of function getone

End of class Blah.

Class AbstractTest: [no user functions]
Class Test: [no user functions]

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
161.97 ms | 1402 KiB | 22 Q