3v4l.org

run code in 300+ PHP versions simultaneously
<?php // User with a protected method class User { protected function getSomething(): string { return 'data from User'; } } // class Student that extend it class Student extends User { public function thisWorks(): void { echo 'Calling protected method from parent: ' . $this->getSomething() . "\n"; } } $s = new Student(); // Note that in this example we call a public method from "the outside" (here). $s->thisWorks(); // This does not work, because this is "global scope". // Protected methods can only be called from withing the class, as in the example above. $s->getSomething();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/093Ao
function name:  (null)
number of ops:  8
compiled vars:  !0 = $s
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   21     0  E >   NEW                                              $1      'Student'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $1
   24     3        INIT_METHOD_CALL                                         !0, 'thisWorks'
          4        DO_FCALL                                      0          
   28     5        INIT_METHOD_CALL                                         !0, 'getSomething'
          6        DO_FCALL                                      0          
          7      > RETURN                                                   1

Class User:
Function getsomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/093Ao
function name:  getSomething
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E > > RETURN                                                   'data+from+User'
    9     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function getsomething

End of class User.

Class Student:
Function thisworks:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/093Ao
function name:  thisWorks
number of ops:  6
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   17     0  E >   INIT_METHOD_CALL                                         'getSomething'
          1        DO_FCALL                                      0  $0      
          2        CONCAT                                           ~1      'Calling+protected+method+from+parent%3A+', $0
          3        CONCAT                                           ~2      ~1, '%0A'
          4        ECHO                                                     ~2
   18     5      > RETURN                                                   null

End of function thisworks

Function getsomething:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/093Ao
function name:  getSomething
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    8     0  E > > RETURN                                                   'data+from+User'
    9     1*       VERIFY_RETURN_TYPE                                       
          2*     > RETURN                                                   null

End of function getsomething

End of class Student.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
158.07 ms | 996 KiB | 13 Q