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 static context $this::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in static context Descendant::staticMethod(); // descendant's staticMethod in static context } static function callMethodsFromStaticContext() { Descendant::publicMethod(); // descendant's publicMethod in static context 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 $descendant::staticMethod(); // descendant's staticMethod in static context Descendant::publicMethod(); // descendant's publicMethod in static context 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 "\n----- 2.1 access to properties from static context -----\n"; $descendant->callToPropertiesFromStaticContext(); echo "\n----- 2.1 access to methods from public context -----\n"; $descendant->callMethodsFromPublicContext(); echo "\n----- 2.1 access to methods from static context -----\n"; $descendant->callMethodsFromStaticContext();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/Ff81g
function name:  (null)
number of ops:  44
compiled vars:  !0 = $ancestor, !1 = $descendant
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   80     0  E >   NEW                                              $2      'Ancestor'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   81     3        NEW                                              $5      'Descendant'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   83     6        ECHO                                                     '%0A1.+From+Outside+Of+An+Instance%2FClass%3A%0A'
   84     7        ECHO                                                     '%0A-----+1.1+access+to+properties+-----%0A'
   85     8        FETCH_OBJ_R                                      ~8      !1, 'publicVar'
          9        ECHO                                                     ~8
   88    10        FETCH_CLASS                                   0  $9      !1
         11        FETCH_STATIC_PROP_R          unknown             ~10     'staticVar'
         12        ECHO                                                     ~10
   91    13        FETCH_STATIC_PROP_R          unknown             ~11     'staticVar'
         14        ECHO                                                     ~11
   93    15        ECHO                                                     '%0A-----+1.2+access+to+methods+-----%0A'
   94    16        INIT_METHOD_CALL                                         !1, 'publicMethod'
         17        DO_FCALL                                      0          
   95    18        INIT_METHOD_CALL                                         !1, 'staticMethod'
         19        DO_FCALL                                      0          
   96    20        FETCH_CLASS                                   0  $14     !1
         21        INIT_STATIC_METHOD_CALL                                  $14, 'publicMethod'
         22        DO_FCALL                                      0          
   97    23        FETCH_CLASS                                   0  $16     !1
         24        INIT_STATIC_METHOD_CALL                                  $16, 'staticMethod'
         25        DO_FCALL                                      0          
   99    26        INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
         27        DO_FCALL                                      0          
  100    28        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
         29        DO_FCALL                                      0          
  102    30        ECHO                                                     '%0A2.+From+Inside+Of+An+Instance%2FClass%3A%0A'
  103    31        ECHO                                                     '%0A-----+2.1+access+to+properties+from+public+context+-----%0A'
  104    32        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromPublicContext'
         33        DO_FCALL                                      0          
  105    34        ECHO                                                     '%0A-----+2.1+access+to+properties+from+static+context+-----%0A'
  106    35        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromStaticContext'
         36        DO_FCALL                                      0          
  108    37        ECHO                                                     '%0A-----+2.1+access+to+methods+from+public+context+-----%0A'
  109    38        INIT_METHOD_CALL                                         !1, 'callMethodsFromPublicContext'
         39        DO_FCALL                                      0          
  110    40        ECHO                                                     '%0A-----+2.1+access+to+methods+from+static+context+-----%0A'
  111    41        INIT_METHOD_CALL                                         !1, 'callMethodsFromStaticContext'
         42        DO_FCALL                                      0          
         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/Ff81g
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/Ff81g
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/Ff81g
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/Ff81g
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/Ff81g
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/Ff81g
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/Ff81g
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          
   72    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/Ff81g
function name:  callMethodsFromStaticContext
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   75     0  E >   INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
          1        DO_FCALL                                      0          
   76     2        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
          3        DO_FCALL                                      0          
   77     4      > RETURN                                                   null

End of function callmethodsfromstaticcontext

End of class Descendant.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
171.46 ms | 1407 KiB | 13 Q