3v4l.org

run code in 300+ PHP versions simultaneously
<?php /** * This base class defines two methods of interest, one private, one protected. * * It also includes 3 ways to invoke these methods from outside. */ class Base { /** * A private base method */ private function priv() { echo __CLASS__ . PHP_EOL; } /** * Expose the private method */ public function callPriv() { $this->priv(); } /** * Expose either 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 redefines the methods of interest. Will overrides apply ? */ class Child extends Base { /** * A child private method. Does it override the base method ? */ private function priv() { echo __CLASS__ . PHP_EOL; } } $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/gA3v2
function name:  (null)
number of ops:  12
compiled vars:  !0 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   52     0  E >   NEW                                              $1      'Child'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   55     3        INIT_METHOD_CALL                                         !0, 'callPriv'
          4        DO_FCALL                                      0          
   56     5        INIT_METHOD_CALL                                         !0, 'call'
          6        SEND_VAL_EX                                              'priv'
          7        DO_FCALL                                      0          
   57     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/gA3v2
function name:  priv
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   13     0  E >   ECHO                                                     'Base%0A'
   14     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/gA3v2
function name:  callPriv
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_METHOD_CALL                                         'priv'
          1        DO_FCALL                                      0          
   21     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/gA3v2
function name:  call
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     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          
   28     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/gA3v2
function name:  reflect
number of ops:  14
compiled vars:  !0 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     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
   35     6        INIT_METHOD_CALL                                         !0, 'setAccessible'
          7        SEND_VAL_EX                                              <true>
          8        DO_FCALL                                      0          
   36     9        INIT_METHOD_CALL                                         !0, 'invoke'
         10        FETCH_THIS                                       $6      
         11        SEND_VAR_EX                                              $6
         12        DO_FCALL                                      0          
   37    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/gA3v2
function name:  priv
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   ECHO                                                     'Child%0A'
   49     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/gA3v2
function name:  callPriv
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   20     0  E >   INIT_METHOD_CALL                                         'priv'
          1        DO_FCALL                                      0          
   21     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/gA3v2
function name:  call
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   27     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          
   28     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/gA3v2
function name:  reflect
number of ops:  14
compiled vars:  !0 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   34     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
   35     6        INIT_METHOD_CALL                                         !0, 'setAccessible'
          7        SEND_VAL_EX                                              <true>
          8        DO_FCALL                                      0          
   36     9        INIT_METHOD_CALL                                         !0, 'invoke'
         10        FETCH_THIS                                       $6      
         11        SEND_VAR_EX                                              $6
         12        DO_FCALL                                      0          
   37    13      > RETURN                                                   null

End of function reflect

End of class Child.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
175.25 ms | 1403 KiB | 13 Q