3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Base { private $basePrivate = 'private in base class'; protected $baseProtected = 'protected in base class'; public $basePublic = 'public in base class'; public function baseExample() { // We *can't* access $this->doesNotExist because it doesn't exist. echo $this->doesNotExist; //ERROR // We *can* access the following: echo __LINE__ . ': ' . $this->basePrivate . "\n"; //OK echo __LINE__ . ': ' . $this->baseProtected . "\n"; //OK echo __LINE__ . ': ' . $this->basePublic . "\n"; //OK } } class Child extends Base { private $childPrivate = 'private in child class'; protected $childProtected = 'protected in child class'; public $childPublic = 'public in child class'; public function childExample() { // We can't access $this->basePrivate because the base class // declared it as private (this is the what private means) echo $this->basePrivate; //ERROR // We can't access $this->doesNotExist because it doesn't exist. echo $this->doesNotExist; //ERROR // We *can* access the following: echo __LINE__ . ': ' . $this->baseProtected . "\n"; //OK echo __LINE__ . ': ' . $this->basePublic . "\n"; //OK echo __LINE__ . ': ' . $this->childPrivate . "\n"; //OK echo __LINE__ . ': ' . $this->childProtected . "\n"; //OK echo __LINE__ . ': ' . $this->childPublic . "\n"; //OK } } // Now we'll create instances of these classes. Since we're now outside of the // classes (i.e. we're using instances of the classes and not in the actual code of the class) // we can now only access public properties. $base = new Base; $child = new Child; // Let's run our demo methods to see the results echo $base->baseExample(); echo $child->childExample(); // Outside the class, we *can't* access the following: echo $base->doesNotExist; //ERROR echo $base->basePrivate; //ERROR echo $base->baseProtected; //ERROR echo $child->doesNotExist; //ERROR echo $child->basePrivate; //ERROR echo $child->baseProtected; //ERROR echo $child->childPrivate; //ERROR echo $child->childProtected; //ERROR // Outside the class, we *can* access public properties echo __LINE__ . ': ' . $base->basePublic . "\n"; //OK echo __LINE__ . ': ' . $child->basePublic . "\n"; //OK echo __LINE__ . ': ' . $child->childPublic . "\n"; //OK
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iYo9i
function name:  (null)
number of ops:  41
compiled vars:  !0 = $base, !1 = $child
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   48     0  E >   NEW                                              $2      'Base'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   49     3        NEW                                              $5      'Child'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   52     6        INIT_METHOD_CALL                                         !0, 'baseExample'
          7        DO_FCALL                                      0  $8      
          8        ECHO                                                     $8
   53     9        INIT_METHOD_CALL                                         !1, 'childExample'
         10        DO_FCALL                                      0  $9      
         11        ECHO                                                     $9
   56    12        FETCH_OBJ_R                                      ~10     !0, 'doesNotExist'
         13        ECHO                                                     ~10
   57    14        FETCH_OBJ_R                                      ~11     !0, 'basePrivate'
         15        ECHO                                                     ~11
   58    16        FETCH_OBJ_R                                      ~12     !0, 'baseProtected'
         17        ECHO                                                     ~12
   59    18        FETCH_OBJ_R                                      ~13     !1, 'doesNotExist'
         19        ECHO                                                     ~13
   60    20        FETCH_OBJ_R                                      ~14     !1, 'basePrivate'
         21        ECHO                                                     ~14
   61    22        FETCH_OBJ_R                                      ~15     !1, 'baseProtected'
         23        ECHO                                                     ~15
   62    24        FETCH_OBJ_R                                      ~16     !1, 'childPrivate'
         25        ECHO                                                     ~16
   63    26        FETCH_OBJ_R                                      ~17     !1, 'childProtected'
         27        ECHO                                                     ~17
   66    28        FETCH_OBJ_R                                      ~18     !0, 'basePublic'
         29        CONCAT                                           ~19     '66%3A+', ~18
         30        CONCAT                                           ~20     ~19, '%0A'
         31        ECHO                                                     ~20
   67    32        FETCH_OBJ_R                                      ~21     !1, 'basePublic'
         33        CONCAT                                           ~22     '67%3A+', ~21
         34        CONCAT                                           ~23     ~22, '%0A'
         35        ECHO                                                     ~23
   68    36        FETCH_OBJ_R                                      ~24     !1, 'childPublic'
         37        CONCAT                                           ~25     '68%3A+', ~24
         38        CONCAT                                           ~26     ~25, '%0A'
         39        ECHO                                                     ~26
         40      > RETURN                                                   1

Class Base:
Function baseexample:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iYo9i
function name:  baseExample
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'doesNotExist'
          1        ECHO                                                     ~0
   15     2        FETCH_OBJ_R                                      ~1      'basePrivate'
          3        CONCAT                                           ~2      '15%3A+', ~1
          4        CONCAT                                           ~3      ~2, '%0A'
          5        ECHO                                                     ~3
   16     6        FETCH_OBJ_R                                      ~4      'baseProtected'
          7        CONCAT                                           ~5      '16%3A+', ~4
          8        CONCAT                                           ~6      ~5, '%0A'
          9        ECHO                                                     ~6
   17    10        FETCH_OBJ_R                                      ~7      'basePublic'
         11        CONCAT                                           ~8      '17%3A+', ~7
         12        CONCAT                                           ~9      ~8, '%0A'
         13        ECHO                                                     ~9
   18    14      > RETURN                                                   null

End of function baseexample

End of class Base.

Class Child:
Function childexample:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iYo9i
function name:  childExample
number of ops:  25
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   FETCH_OBJ_R                                      ~0      'basePrivate'
          1        ECHO                                                     ~0
   34     2        FETCH_OBJ_R                                      ~1      'doesNotExist'
          3        ECHO                                                     ~1
   37     4        FETCH_OBJ_R                                      ~2      'baseProtected'
          5        CONCAT                                           ~3      '37%3A+', ~2
          6        CONCAT                                           ~4      ~3, '%0A'
          7        ECHO                                                     ~4
   38     8        FETCH_OBJ_R                                      ~5      'basePublic'
          9        CONCAT                                           ~6      '38%3A+', ~5
         10        CONCAT                                           ~7      ~6, '%0A'
         11        ECHO                                                     ~7
   39    12        FETCH_OBJ_R                                      ~8      'childPrivate'
         13        CONCAT                                           ~9      '39%3A+', ~8
         14        CONCAT                                           ~10     ~9, '%0A'
         15        ECHO                                                     ~10
   40    16        FETCH_OBJ_R                                      ~11     'childProtected'
         17        CONCAT                                           ~12     '40%3A+', ~11
         18        CONCAT                                           ~13     ~12, '%0A'
         19        ECHO                                                     ~13
   41    20        FETCH_OBJ_R                                      ~14     'childPublic'
         21        CONCAT                                           ~15     '41%3A+', ~14
         22        CONCAT                                           ~16     ~15, '%0A'
         23        ECHO                                                     ~16
   42    24      > RETURN                                                   null

End of function childexample

Function baseexample:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/iYo9i
function name:  baseExample
number of ops:  15
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   12     0  E >   FETCH_OBJ_R                                      ~0      'doesNotExist'
          1        ECHO                                                     ~0
   15     2        FETCH_OBJ_R                                      ~1      'basePrivate'
          3        CONCAT                                           ~2      '15%3A+', ~1
          4        CONCAT                                           ~3      ~2, '%0A'
          5        ECHO                                                     ~3
   16     6        FETCH_OBJ_R                                      ~4      'baseProtected'
          7        CONCAT                                           ~5      '16%3A+', ~4
          8        CONCAT                                           ~6      ~5, '%0A'
          9        ECHO                                                     ~6
   17    10        FETCH_OBJ_R                                      ~7      'basePublic'
         11        CONCAT                                           ~8      '17%3A+', ~7
         12        CONCAT                                           ~9      ~8, '%0A'
         13        ECHO                                                     ~9
   18    14      > RETURN                                                   null

End of function baseexample

End of class Child.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
157.09 ms | 1403 KiB | 13 Q