3v4l.org

run code in 300+ PHP versions simultaneously
<?php class Ancestor { public $publicVar = "ancestor's public var\n"; static $staticVar = "ancestor's static var\n"; function publicMethod(){ echo "ancestor's publicMethod "; // is $this is set up if(isset($this)){ echo "is in object context\n"; }else{ echo "is in static context\n"; } } static function staticMethod(){ echo "ancestor's staticMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "in static context\n"; } } } class Descendant extends Ancestor { public $publicVar = "descendant's public var\n"; static $staticVar = "descendant's static var\n"; function publicMethod(){ echo "descendant's publicMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "in static context\n"; } } static function staticMethod(){ echo "descendant's staticMethod "; // is $this is set up if(isset($this)){ echo "in object context\n"; }else{ echo "in static context\n"; } } function callToPropertiesFromPublicContext(){ echo $this->publicVar; // descendant's public var //echo $this->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $this::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo $this::$staticVar; // descendant's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo Descendant::$staticVar; // descendant's static var } static function callToPropertiesFromStaticContext(){ //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo Descendant::$staticVar; // descendant's static var } function callMethodsFromPublicContext() { $this->publicMethod(); // descendant's publicMethod in object context $this->staticMethod(); // descendant's staticMethod in static context $this::publicMethod(); // descendant's publicMethod in object context $this::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in object context Descendant::staticMethod(); // descendant's staticMethod in static context } static function callMethodsFromStaticContext() { Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) Descendant::staticMethod(); // descendant's staticMethod in static context } } $ancestor = new Ancestor(); $descendant = new Descendant(); echo "\n1. From Outside Of An Instance/Class:\n"; echo "\n----- 1.1 access to properties -----\n"; echo $descendant->publicVar; // descendant's public var //echo $descendant->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar echo $descendant::$staticVar; // descendant's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property echo Descendant::$staticVar; // descendant's static var echo "\n----- 1.2 access to methods -----\n"; $descendant->publicMethod(); // descendant's publicMethod in object context $descendant->staticMethod(); // descendant's staticMethod in static context $descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) $descendant::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) Descendant::staticMethod(); // descendant's staticMethod in static context echo "\n2. From Inside Of An Instance/Class:\n"; echo "\n----- 2.1 access to properties from public context -----\n"; $descendant->callToPropertiesFromPublicContext(); //echo $this->publicVar; // descendant's public var //echo $this->staticVar; // "" + notice: Undefined property: Descendant::$staticVar //echo $this::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo $this::$staticVar; // descendant's static var // //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Descendant::$staticVar; // descendant's static var echo "\n----- 2.2 access to properties from static context -----\n"; $descendant->callToPropertiesFromStaticContext(); //echo Descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Descendant::$staticVar; // descendant's static var echo "\n----- 2.3 access to methods from public context -----\n"; $descendant->callMethodsFromPublicContext(); //$this->publicMethod(); // descendant's publicMethod in object context //$this->staticMethod(); // descendant's staticMethod in static context //$this::publicMethod(); // descendant's publicMethod in object context //$this::staticMethod(); // descendant's staticMethod in static context // //Descendant::publicMethod(); // descendant's publicMethod in object context //Descendant::staticMethod(); // descendant's staticMethod in static context echo "\n----- 2.4 access to methods from static context -----\n"; $descendant->callMethodsFromStaticContext(); //Descendant::publicMethod(); // descendant's publicMethod in static context (deprecated) //Descendant::staticMethod(); // descendant's staticMethod in static context
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  (null)
number of ops:  44
compiled vars:  !0 = $ancestor, !1 = $descendant
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   81     0  E >   NEW                                              $2      'Ancestor'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   82     3        NEW                                              $5      'Descendant'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   84     6        ECHO                                                     '%0A1.+From+Outside+Of+An+Instance%2FClass%3A%0A'
   85     7        ECHO                                                     '%0A-----+1.1+access+to+properties+-----%0A'
   86     8        FETCH_OBJ_R                                      ~8      !1, 'publicVar'
          9        ECHO                                                     ~8
   89    10        FETCH_CLASS                                   0  $9      !1
         11        FETCH_STATIC_PROP_R          unknown             ~10     'staticVar'
         12        ECHO                                                     ~10
   92    13        FETCH_STATIC_PROP_R          unknown             ~11     'staticVar'
         14        ECHO                                                     ~11
   94    15        ECHO                                                     '%0A-----+1.2+access+to+methods+-----%0A'
   95    16        INIT_METHOD_CALL                                         !1, 'publicMethod'
         17        DO_FCALL                                      0          
   96    18        INIT_METHOD_CALL                                         !1, 'staticMethod'
         19        DO_FCALL                                      0          
   97    20        FETCH_CLASS                                   0  $14     !1
         21        INIT_STATIC_METHOD_CALL                                  $14, 'publicMethod'
         22        DO_FCALL                                      0          
   98    23        FETCH_CLASS                                   0  $16     !1
         24        INIT_STATIC_METHOD_CALL                                  $16, 'staticMethod'
         25        DO_FCALL                                      0          
  100    26        INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
         27        DO_FCALL                                      0          
  101    28        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
         29        DO_FCALL                                      0          
  103    30        ECHO                                                     '%0A2.+From+Inside+Of+An+Instance%2FClass%3A%0A'
  104    31        ECHO                                                     '%0A-----+2.1+access+to+properties+from+public+context+-----%0A'
  105    32        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromPublicContext'
         33        DO_FCALL                                      0          
  113    34        ECHO                                                     '%0A-----+2.2+access+to+properties+from+static+context+-----%0A'
  114    35        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromStaticContext'
         36        DO_FCALL                                      0          
  118    37        ECHO                                                     '%0A-----+2.3+access+to+methods+from+public+context+-----%0A'
  119    38        INIT_METHOD_CALL                                         !1, 'callMethodsFromPublicContext'
         39        DO_FCALL                                      0          
  127    40        ECHO                                                     '%0A-----+2.4+access+to+methods+from+static+context+-----%0A'
  128    41        INIT_METHOD_CALL                                         !1, 'callMethodsFromStaticContext'
         42        DO_FCALL                                      0          
  130    43      > RETURN                                                   1

Class Ancestor:
Function publicmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  publicMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ECHO                                                     'ancestor%27s+publicMethod+'
    8     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
    9     3    >   ECHO                                                     'is+in+object+context%0A'
          4      > JMP                                                      ->6
   11     5    >   ECHO                                                     'is+in+static+context%0A'
   13     6    > > RETURN                                                   null

End of function publicmethod

Function staticmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  staticMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ECHO                                                     'ancestor%27s+staticMethod+'
   18     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   19     3    >   ECHO                                                     'in+object+context%0A'
          4      > JMP                                                      ->6
   21     5    >   ECHO                                                     'in+static+context%0A'
   23     6    > > RETURN                                                   null

End of function staticmethod

End of class Ancestor.

Class Descendant:
Function publicmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  publicMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'descendant%27s+publicMethod+'
   33     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   34     3    >   ECHO                                                     'in+object+context%0A'
          4      > JMP                                                      ->6
   36     5    >   ECHO                                                     'in+static+context%0A'
   38     6    > > RETURN                                                   null

End of function publicmethod

Function staticmethod:
Finding entry points
Branch analysis from position: 0
2 jumps found. (Code = 43) Position 1 = 3, Position 2 = 5
Branch analysis from position: 3
1 jumps found. (Code = 42) Position 1 = 6
Branch analysis from position: 6
1 jumps found. (Code = 62) Position 1 = -2
Branch analysis from position: 5
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  staticMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ECHO                                                     'descendant%27s+staticMethod+'
   43     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   44     3    >   ECHO                                                     'in+object+context%0A'
          4      > JMP                                                      ->6
   46     5    >   ECHO                                                     'in+static+context%0A'
   48     6    > > RETURN                                                   null

End of function staticmethod

Function calltopropertiesfrompubliccontext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  callToPropertiesFromPublicContext
number of ops:  9
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'publicVar'
          1        ECHO                                                     ~0
   54     2        FETCH_THIS                                       ~1      
          3        FETCH_CLASS                                   0  $2      ~1
          4        FETCH_STATIC_PROP_R          unknown             ~3      'staticVar'
          5        ECHO                                                     ~3
   56     6        FETCH_STATIC_PROP_R          unknown             ~4      'staticVar'
          7        ECHO                                                     ~4
   57     8      > RETURN                                                   null

End of function calltopropertiesfrompubliccontext

Function calltopropertiesfromstaticcontext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  callToPropertiesFromStaticContext
number of ops:  3
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   60     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'staticVar'
          1        ECHO                                                     ~0
   61     2      > RETURN                                                   null

End of function calltopropertiesfromstaticcontext

Function callmethodsfrompubliccontext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  callMethodsFromPublicContext
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   65     0  E >   INIT_METHOD_CALL                                         'publicMethod'
          1        DO_FCALL                                      0          
   66     2        INIT_METHOD_CALL                                         'staticMethod'
          3        DO_FCALL                                      0          
   67     4        FETCH_THIS                                       ~2      
          5        FETCH_CLASS                                   0  $3      ~2
          6        INIT_STATIC_METHOD_CALL                                  $3, 'publicMethod'
          7        DO_FCALL                                      0          
   68     8        FETCH_THIS                                       ~5      
          9        FETCH_CLASS                                   0  $6      ~5
         10        INIT_STATIC_METHOD_CALL                                  $6, 'staticMethod'
         11        DO_FCALL                                      0          
   70    12        INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
         13        DO_FCALL                                      0          
   71    14        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
         15        DO_FCALL                                      0          
   73    16      > RETURN                                                   null

End of function callmethodsfrompubliccontext

Function callmethodsfromstaticcontext:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/OhvI2
function name:  callMethodsFromStaticContext
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   76     0  E >   INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
          1        DO_FCALL                                      0          
   77     2        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
          3        DO_FCALL                                      0          
   78     4      > RETURN                                                   null

End of function callmethodsfromstaticcontext

End of class Descendant.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
174.41 ms | 1411 KiB | 13 Q