3v4l.org

run code in 300+ PHP versions simultaneously
<?php trait x { public function bar() { echo 'Trait x bar()'; } public function foo() { echo 'Trait x foo()'; } } class z { use x; public function foo() { echo 'Class foo()'; } } function getClassAndTraitMethods(ReflectionClass $class) { $traitMethods = []; foreach($class->getTraits() as $trait) { foreach($trait->getMethods() as $method) { $traitMethods[] = $method; } } $traitRefs = []; foreach($traitMethods as $traitMethod) { $traitRefs[spl_object_hash($traitMethod)]=$traitMethod->name; } $classMethods = []; $classRefs = []; foreach($class->getMethods() as $classMethod) { $classMethods[]=$classMethod; $classRefs[spl_object_hash($classMethod)] = $classMethod->name; } return ['traitRefs'=>$traitRefs,'classRefs'=>$classRefs]; } $obj = new z; $ref = new ReflectionClass($obj); extract(getClassAndTraitMethods($ref)); $traitOnlyHashes = array_diff( array_keys($traitRefs), array_keys($classRefs) ); $traitOnlyMethods = array_intersect_key($traitRefs, array_flip($traitOnlyHashes)); print_r($traitRefs); print_r($classRefs); print_r($traitOnlyMethods);
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CqEW3
function name:  (null)
number of ops:  43
compiled vars:  !0 = $obj, !1 = $ref, !2 = $traitOnlyHashes, !3 = $traitRefs, !4 = $classRefs, !5 = $traitOnlyMethods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   DECLARE_CLASS                                            'z'
   54     1        NEW                                              $6      'z'
          2        DO_FCALL                                      0          
          3        ASSIGN                                                   !0, $6
   55     4        NEW                                              $9      'ReflectionClass'
          5        SEND_VAR_EX                                              !0
          6        DO_FCALL                                      0          
          7        ASSIGN                                                   !1, $9
   57     8        INIT_FCALL                                               'extract'
          9        INIT_FCALL                                               'getclassandtraitmethods'
         10        SEND_VAR                                                 !1
         11        DO_FCALL                                      0  $12     
         12        SEND_VAL                                                 $12
         13        DO_ICALL                                                 
   59    14        INIT_FCALL                                               'array_diff'
   60    15        INIT_FCALL                                               'array_keys'
         16        SEND_VAR                                                 !3
         17        DO_ICALL                                         $14     
         18        SEND_VAR                                                 $14
   61    19        INIT_FCALL                                               'array_keys'
         20        SEND_VAR                                                 !4
         21        DO_ICALL                                         $15     
         22        SEND_VAR                                                 $15
   59    23        DO_ICALL                                         $16     
         24        ASSIGN                                                   !2, $16
   64    25        INIT_FCALL                                               'array_intersect_key'
         26        SEND_VAR                                                 !3
         27        INIT_FCALL                                               'array_flip'
         28        SEND_VAR                                                 !2
         29        DO_ICALL                                         $18     
         30        SEND_VAR                                                 $18
         31        DO_ICALL                                         $19     
         32        ASSIGN                                                   !5, $19
   66    33        INIT_FCALL                                               'print_r'
         34        SEND_VAR                                                 !3
         35        DO_ICALL                                                 
   67    36        INIT_FCALL                                               'print_r'
         37        SEND_VAR                                                 !4
         38        DO_ICALL                                                 
   68    39        INIT_FCALL                                               'print_r'
         40        SEND_VAR                                                 !5
         41        DO_ICALL                                                 
         42      > RETURN                                                   1

Function getclassandtraitmethods:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 77) Position 1 = 5, Position 2 = 15
Branch analysis from position: 5
2 jumps found. (Code = 78) Position 1 = 6, Position 2 = 15
Branch analysis from position: 6
2 jumps found. (Code = 77) Position 1 = 9, Position 2 = 13
Branch analysis from position: 9
2 jumps found. (Code = 78) Position 1 = 10, Position 2 = 13
Branch analysis from position: 10
1 jumps found. (Code = 42) Position 1 = 9
Branch analysis from position: 9
Branch analysis from position: 13
1 jumps found. (Code = 42) Position 1 = 5
Branch analysis from position: 5
Branch analysis from position: 13
Branch analysis from position: 15
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
2 jumps found. (Code = 77) Position 1 = 32, Position 2 = 42
Branch analysis from position: 32
2 jumps found. (Code = 78) Position 1 = 33, Position 2 = 42
Branch analysis from position: 33
1 jumps found. (Code = 42) Position 1 = 32
Branch analysis from position: 32
Branch analysis from position: 42
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 42
Branch analysis from position: 26
Branch analysis from position: 15
filename:       /in/CqEW3
function name:  getClassAndTraitMethods
number of ops:  47
compiled vars:  !0 = $class, !1 = $traitMethods, !2 = $trait, !3 = $method, !4 = $traitRefs, !5 = $traitMethod, !6 = $classMethods, !7 = $classRefs, !8 = $classMethod
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        ASSIGN                                                   !1, <array>
   30     2        INIT_METHOD_CALL                                         !0, 'getTraits'
          3        DO_FCALL                                      0  $10     
          4      > FE_RESET_R                                       $11     $10, ->15
          5    > > FE_FETCH_R                                               $11, !2, ->15
   32     6    >   INIT_METHOD_CALL                                         !2, 'getMethods'
          7        DO_FCALL                                      0  $12     
          8      > FE_RESET_R                                       $13     $12, ->13
          9    > > FE_FETCH_R                                               $13, !3, ->13
   34    10    >   ASSIGN_DIM                                               !1
         11        OP_DATA                                                  !3
   32    12      > JMP                                                      ->9
         13    >   FE_FREE                                                  $13
   30    14      > JMP                                                      ->5
         15    >   FE_FREE                                                  $11
   37    16        ASSIGN                                                   !4, <array>
   38    17      > FE_RESET_R                                       $16     !1, ->26
         18    > > FE_FETCH_R                                               $16, !5, ->26
   40    19    >   INIT_FCALL                                               'spl_object_hash'
         20        SEND_VAR                                                 !5
         21        DO_ICALL                                         $17     
         22        FETCH_OBJ_R                                      ~19     !5, 'name'
         23        ASSIGN_DIM                                               !4, $17
         24        OP_DATA                                                  ~19
   38    25      > JMP                                                      ->18
         26    >   FE_FREE                                                  $16
   43    27        ASSIGN                                                   !6, <array>
   44    28        ASSIGN                                                   !7, <array>
   45    29        INIT_METHOD_CALL                                         !0, 'getMethods'
         30        DO_FCALL                                      0  $22     
         31      > FE_RESET_R                                       $23     $22, ->42
         32    > > FE_FETCH_R                                               $23, !8, ->42
   47    33    >   ASSIGN_DIM                                               !6
         34        OP_DATA                                                  !8
   48    35        INIT_FCALL                                               'spl_object_hash'
         36        SEND_VAR                                                 !8
         37        DO_ICALL                                         $25     
         38        FETCH_OBJ_R                                      ~27     !8, 'name'
         39        ASSIGN_DIM                                               !7, $25
         40        OP_DATA                                                  ~27
   45    41      > JMP                                                      ->32
         42    >   FE_FREE                                                  $23
   51    43        INIT_ARRAY                                       ~28     !4, 'traitRefs'
         44        ADD_ARRAY_ELEMENT                                ~28     !7, 'classRefs'
         45      > RETURN                                                   ~28
   52    46*     > RETURN                                                   null

End of function getclassandtraitmethods

Class x:
Function bar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CqEW3
function name:  bar
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    7     0  E >   ECHO                                                     'Trait+x+bar%28%29'
    8     1      > RETURN                                                   null

End of function bar

Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CqEW3
function name:  foo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   ECHO                                                     'Trait+x+foo%28%29'
   13     1      > RETURN                                                   null

End of function foo

End of class x.

Class z:
Function foo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/CqEW3
function name:  foo
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   22     0  E >   ECHO                                                     'Class+foo%28%29'
   23     1      > RETURN                                                   null

End of function foo

End of class z.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
149.03 ms | 1455 KiB | 21 Q