3v4l.org

run code in 500+ PHP versions simultaneously
<?php class YoProvider { protected function getYo() { return 'yo'; } } trait testTrait { function invokeProtectedMethod($object, $method) { $rm = new ReflectionMethod($object, $method); if ($rm->isProtected()) { $rm->setAccessible(TRUE); return $rm->invoke($object); } } } class testClass { use testTrait; function testYoProvider() { $yo_provider = new YoProvider(); $yo = $this->invokeProtectedMethod($yo_provider, 'getYo'); print $yo; // $this->assertEquals('yo', $yo); } } (new testClass())->testYoProvider();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rK9r7
function name:  (null)
number of ops:  6
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   19     0  E >   DECLARE_CLASS                                                'testclass'
   29     1        NEW                                                  $0      'testClass'
          2        DO_FCALL                                          0          
          3        INIT_METHOD_CALL                                             $0, 'testYoProvider'
          4        DO_FCALL                                          0          
          5      > RETURN                                                       1

Class YoProvider:
Function getyo:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rK9r7
function name:  getYo
number of ops:  2
compiled vars:  none
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
    5     0  E > > RETURN                                                       'yo'
    6     1*     > RETURN                                                       null

End of function getyo

End of class YoProvider.

Class testTrait:
Function invokeprotectedmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 10, Position 2 = 17
Branch analysis from position: 10
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 17
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rK9r7
function name:  invokeProtectedMethod
number of ops:  18
compiled vars:  !0 = $object, !1 = $method, !2 = $rm
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   10     0  E >   RECV                                                 !0      
          1        RECV                                                 !1      
   11     2        NEW                                                  $3      'ReflectionMethod'
          3        SEND_VAR_EX                                                  !0
          4        SEND_VAR_EX                                                  !1
          5        DO_FCALL                                          0          
          6        ASSIGN                                                       !2, $3
   12     7        INIT_METHOD_CALL                                             !2, 'isProtected'
          8        DO_FCALL                                          0  $6      
          9      > JMPZ                                                         $6, ->17
   13    10    >   INIT_METHOD_CALL                                             !2, 'setAccessible'
         11        SEND_VAL_EX                                                  <true>
         12        DO_FCALL                                          0          
   14    13        INIT_METHOD_CALL                                             !2, 'invoke'
         14        SEND_VAR_EX                                                  !0
         15        DO_FCALL                                          0  $8      
         16      > RETURN                                                       $8
   16    17    > > RETURN                                                       null

End of function invokeprotectedmethod

End of class testTrait.

Class testClass:
Function testyoprovider:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rK9r7
function name:  testYoProvider
number of ops:  10
compiled vars:  !0 = $yo_provider, !1 = $yo
line      #* E I O op                               fetch          ext  return  operands
-----------------------------------------------------------------------------------------
   23     0  E >   NEW                                                  $2      'YoProvider'
          1        DO_FCALL                                          0          
          2        ASSIGN                                                       !0, $2
   24     3        INIT_METHOD_CALL                                             'invokeProtectedMethod'
          4        SEND_VAR_EX                                                  !0
          5        SEND_VAL_EX                                                  'getYo'
          6        DO_FCALL                                          0  $5      
          7        ASSIGN                                                       !1, $5
   25     8        ECHO                                                         !1
   26     9      > RETURN                                                       null

End of function testyoprovider

End of class testClass.

Generated using Vulcan Logic Dumper, using php 8.5.0


preferences:
144.85 ms | 480 KiB | 7 Q