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__ . " Private\n"; } /** * A protected base method */ protected function prot() { echo __CLASS__ . " Protected\n"; } /** * Expose the private method */ public function callPriv() { $this->priv(); } /** * Expose the protected method */ public function callProt() { $this->prot(); } /** * Expose either method via call_user_func(). */ public function call($method) { call_user_func([$this, $method]); } /** * Expose either method using Reflection. */ public function reflect($method) { $rm = new ReflectionMethod($this, $method); if (!$rm->isPublic()) { $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__ . " Private\n"; } /** * A child protected method. Does it override the base method ? */ protected function prot() { echo __CLASS__ . " Protected\n"; } } $f = new Child(); $f->callPriv(); $f->call('priv'); $f->reflect('priv'); echo "\n"; $f->callProt(); $f->call('prot'); $f->reflect('prot');
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Aoflo
function name:  (null)
number of ops:  21
compiled vars:  !0 = $f
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   NEW                                              $1      'Child'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   78     3        INIT_METHOD_CALL                                         !0, 'callPriv'
          4        DO_FCALL                                      0          
   79     5        INIT_METHOD_CALL                                         !0, 'call'
          6        SEND_VAL_EX                                              'priv'
          7        DO_FCALL                                      0          
   80     8        INIT_METHOD_CALL                                         !0, 'reflect'
          9        SEND_VAL_EX                                              'priv'
         10        DO_FCALL                                      0          
   82    11        ECHO                                                     '%0A'
   84    12        INIT_METHOD_CALL                                         !0, 'callProt'
         13        DO_FCALL                                      0          
   85    14        INIT_METHOD_CALL                                         !0, 'call'
         15        SEND_VAL_EX                                              'prot'
         16        DO_FCALL                                      0          
   86    17        INIT_METHOD_CALL                                         !0, 'reflect'
         18        SEND_VAL_EX                                              'prot'
         19        DO_FCALL                                      0          
         20      > RETURN                                                   1

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

End of function priv

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

End of function prot

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

End of function callpriv

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

End of function callprot

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

End of function call

Function reflect:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 11, Position 2 = 14
Branch analysis from position: 11
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 14
filename:       /in/Aoflo
function name:  reflect
number of ops:  19
compiled vars:  !0 = $method, !1 = $rm
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   47     0  E >   RECV                                             !0      
   48     1        NEW                                              $2      'ReflectionMethod'
          2        FETCH_THIS                                       $3      
          3        SEND_VAR_EX                                              $3
          4        SEND_VAR_EX                                              !0
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !1, $2
   49     7        INIT_METHOD_CALL                                         !1, 'isPublic'
          8        DO_FCALL                                      0  $6      
          9        BOOL_NOT                                         ~7      $6
         10      > JMPZ                                                     ~7, ->14
   50    11    >   INIT_METHOD_CALL                                         !1, 'setAccessible'
         12        SEND_VAL_EX                                              <true>
         13        DO_FCALL                                      0          
   52    14    >   INIT_METHOD_CALL                                         !1, 'invoke'
         15        FETCH_THIS                                       $9      
         16        SEND_VAR_EX                                              $9
         17        DO_FCALL                                      0          
   53    18      > 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/Aoflo
function name:  priv
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   ECHO                                                     'Child+Private%0A'
   65     1      > RETURN                                                   null

End of function priv

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

End of function prot

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

End of function callpriv

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

End of function callprot

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

End of function call

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

End of function reflect

End of class Child.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
162.83 ms | 1407 KiB | 13 Q