3v4l.org

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

Function gettraitmethodsrefs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mN7In
function name:  getTraitMethodsRefs
number of ops:  25
compiled vars:  !0 = $class, !1 = $traitMethods
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     0  E >   RECV                                             !0      
   29     1        INIT_FCALL                                               'array_merge'
          2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmN7In%3A29%241'
   31     4        SEND_VAL                                                 ~2
          5        INIT_METHOD_CALL                                         !0, 'getTraits'
          6        DO_FCALL                                      0  $3      
          7        SEND_VAR                                                 $3
          8        DO_ICALL                                         $4      
          9        SEND_ARRAY                                               $4
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      0  $5      
   29    12        ASSIGN                                                   !1, $5
   32    13        INIT_FCALL                                               'array_merge'
         14        INIT_FCALL                                               'array_map'
         15        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmN7In%3A32%242'
   34    16        SEND_VAL                                                 ~7
         17        SEND_VAR                                                 !1
         18        DO_ICALL                                         $8      
         19        SEND_ARRAY                                               $8
         20        CHECK_UNDEF_ARGS                                         
         21        DO_FCALL                                      0  $9      
   32    22        ASSIGN                                                   !1, $9
   36    23      > RETURN                                                   !1
   37    24*     > RETURN                                                   null

End of function gettraitmethodsrefs

Function %00%7Bclosure%7D%2Fin%2FmN7In%3A29%241:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mN7In
function name:  {closure}
number of ops:  5
compiled vars:  !0 = $ref
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   29     0  E >   RECV                                             !0      
   30     1        INIT_METHOD_CALL                                         !0, 'getMethods'
          2        DO_FCALL                                      0  $1      
          3      > RETURN                                                   $1
   31     4*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmN7In%3A29%241

Function %00%7Bclosure%7D%2Fin%2FmN7In%3A32%242:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mN7In
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   RECV                                             !0      
   33     1        INIT_FCALL                                               'spl_object_hash'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        INIT_METHOD_CALL                                         !0, 'getName'
          5        DO_FCALL                                      0  $2      
          6        INIT_ARRAY                                       ~3      $2, $1
          7      > RETURN                                                   ~3
   34     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmN7In%3A32%242

Function getclassmethodsrefs:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mN7In
function name:  getClassMethodsRefs
number of ops:  14
compiled vars:  !0 = $class
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   39     0  E >   RECV                                             !0      
   41     1        INIT_FCALL                                               'array_merge'
          2        INIT_FCALL                                               'array_map'
          3        DECLARE_LAMBDA_FUNCTION                                  '%00%7Bclosure%7D%2Fin%2FmN7In%3A41%243'
   43     4        SEND_VAL                                                 ~1
          5        INIT_METHOD_CALL                                         !0, 'getMethods'
          6        DO_FCALL                                      0  $2      
          7        SEND_VAR                                                 $2
          8        DO_ICALL                                         $3      
          9        SEND_ARRAY                                               $3
         10        CHECK_UNDEF_ARGS                                         
         11        DO_FCALL                                      0  $4      
         12      > RETURN                                                   $4
   44    13*     > RETURN                                                   null

End of function getclassmethodsrefs

Function %00%7Bclosure%7D%2Fin%2FmN7In%3A41%243:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/mN7In
function name:  {closure}
number of ops:  9
compiled vars:  !0 = $method
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   RECV                                             !0      
   42     1        INIT_FCALL                                               'spl_object_hash'
          2        SEND_VAR                                                 !0
          3        DO_ICALL                                         $1      
          4        INIT_METHOD_CALL                                         !0, 'getName'
          5        DO_FCALL                                      0  $2      
          6        INIT_ARRAY                                       ~3      $2, $1
          7      > RETURN                                                   ~3
   43     8*     > RETURN                                                   null

End of function %00%7Bclosure%7D%2Fin%2FmN7In%3A41%243

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

End of function foo

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

End of function bar

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/mN7In
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:
180.06 ms | 1411 KiB | 31 Q