3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base { private function priv() { echo "Base\n"; } // Expose the private method directly. public function callPriv() { $this->priv(); } // Expose the method via call_user_func(). public function call() { call_user_func(array($this, 'priv')); } // Expose either method using Reflection. public function reflect() { $rm = new ReflectionMethod($this, 'priv'); $rm->setAccessible(true); $rm->invoke($this); } } class Child extends Base { // A child private method. Does it override the base method ? private function priv() { echo "Child\n"; } // Expose the private method directly. public function callPriv() { $this->priv(); } } $f = new Child(); // Shouldn't instance method calls invoke the method from the instance class ? $f->callPriv(); $f->call('priv'); $f->reflect('priv');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  (null)
number of ops:  12
compiled vars:  !0 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   37     0  E >   NEW                                              $1      'Child'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   40     3        INIT_METHOD_CALL                                         !0, 'callPriv'
          4        DO_FCALL                                      0          
   41     5        INIT_METHOD_CALL                                         !0, 'call'
          6        SEND_VAL_EX                                              'priv'
          7        DO_FCALL                                      0          
   42     8        INIT_METHOD_CALL                                         !0, 'reflect'
          9        SEND_VAL_EX                                              'priv'
         10        DO_FCALL                                      0          
         11      > RETURN                                                   1

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

End of function priv

Function callpriv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  callPriv
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    9     0  E >   INIT_METHOD_CALL                                         'priv'
          1        DO_FCALL                                      0          
   10     2      > RETURN                                                   null

End of function callpriv

Function call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  call
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_THIS                                       ~0      
          1        INIT_ARRAY                                       ~1      ~0
          2        ADD_ARRAY_ELEMENT                                ~1      'priv'
          3        INIT_USER_CALL                                0          'call_user_func', ~1
          4        DO_FCALL                                      0          
   15     5      > RETURN                                                   null

End of function call

Function reflect:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  reflect
number of ops:  14
compiled vars:  !0 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $1      'ReflectionMethod'
          1        FETCH_THIS                                       $2      
          2        SEND_VAR_EX                                              $2
          3        SEND_VAL_EX                                              'priv'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   20     6        INIT_METHOD_CALL                                         !0, 'setAccessible'
          7        SEND_VAL_EX                                              <true>
          8        DO_FCALL                                      0          
   21     9        INIT_METHOD_CALL                                         !0, 'invoke'
         10        FETCH_THIS                                       $6      
         11        SEND_VAR_EX                                              $6
         12        DO_FCALL                                      0          
   22    13      > RETURN                                                   null

End of function reflect

End of class Base.

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

End of function priv

Function callpriv:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  callPriv
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   32     0  E >   INIT_METHOD_CALL                                         'priv'
          1        DO_FCALL                                      0          
   33     2      > RETURN                                                   null

End of function callpriv

Function call:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  call
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_THIS                                       ~0      
          1        INIT_ARRAY                                       ~1      ~0
          2        ADD_ARRAY_ELEMENT                                ~1      'priv'
          3        INIT_USER_CALL                                0          'call_user_func', ~1
          4        DO_FCALL                                      0          
   15     5      > RETURN                                                   null

End of function call

Function reflect:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/rriqc
function name:  reflect
number of ops:  14
compiled vars:  !0 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   19     0  E >   NEW                                              $1      'ReflectionMethod'
          1        FETCH_THIS                                       $2      
          2        SEND_VAR_EX                                              $2
          3        SEND_VAL_EX                                              'priv'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !0, $1
   20     6        INIT_METHOD_CALL                                         !0, 'setAccessible'
          7        SEND_VAL_EX                                              <true>
          8        DO_FCALL                                      0          
   21     9        INIT_METHOD_CALL                                         !0, 'invoke'
         10        FETCH_THIS                                       $6      
         11        SEND_VAR_EX                                              $6
         12        DO_FCALL                                      0          
   22    13      > RETURN                                                   null

End of function reflect

End of class Child.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.74 ms | 1403 KiB | 13 Q