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; // fatal error: Access to undeclared static property: Descendant::$publicVar echo $this::$publicVar; // echo $this::$staticVar; echo Descendant::$publicVar; echo Descendant::$staticVar; } static function callToPropertiesFromStaticContext(){ echo Descendant::$publicVar; echo Descendant::$staticVar; } } $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();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/R2hos
function name:  (null)
number of ops:  38
compiled vars:  !0 = $ancestor, !1 = $descendant
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   64     0  E >   NEW                                              $2      'Ancestor'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   65     3        NEW                                              $5      'Descendant'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   67     6        ECHO                                                     '%0A1.+From+Outside+Of+An+Instance%2FClass%3A%0A'
   68     7        ECHO                                                     '%0A-----+1.1+access+to+properties+-----%0A'
   69     8        FETCH_OBJ_R                                      ~8      !1, 'publicVar'
          9        ECHO                                                     ~8
   72    10        FETCH_CLASS                                   0  $9      !1
         11        FETCH_STATIC_PROP_R          unknown             ~10     'staticVar'
         12        ECHO                                                     ~10
   75    13        FETCH_STATIC_PROP_R          unknown             ~11     'staticVar'
         14        ECHO                                                     ~11
   77    15        ECHO                                                     '%0A-----+1.2+access+to+methods+-----%0A'
   78    16        INIT_METHOD_CALL                                         !1, 'publicMethod'
         17        DO_FCALL                                      0          
   79    18        INIT_METHOD_CALL                                         !1, 'staticMethod'
         19        DO_FCALL                                      0          
   80    20        FETCH_CLASS                                   0  $14     !1
         21        INIT_STATIC_METHOD_CALL                                  $14, 'publicMethod'
         22        DO_FCALL                                      0          
   81    23        FETCH_CLASS                                   0  $16     !1
         24        INIT_STATIC_METHOD_CALL                                  $16, 'staticMethod'
         25        DO_FCALL                                      0          
   83    26        INIT_STATIC_METHOD_CALL                                  'Descendant', 'publicMethod'
         27        DO_FCALL                                      0          
   84    28        INIT_STATIC_METHOD_CALL                                  'Descendant', 'staticMethod'
         29        DO_FCALL                                      0          
   86    30        ECHO                                                     '%0A2.+From+Inside+Of+An+Instance%2FClass%3A%0A'
   87    31        ECHO                                                     '%0A-----+2.1+access+to+properties+from+public+context+-----%0A'
   88    32        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromPublicContext'
         33        DO_FCALL                                      0          
   89    34        ECHO                                                     '%0A-----+2.1+access+to+properties+from+static+context+-----%0A'
   90    35        INIT_METHOD_CALL                                         !1, 'callToPropertiesFromStaticContext'
         36        DO_FCALL                                      0          
         37      > 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/R2hos
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/R2hos
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/R2hos
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/R2hos
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/R2hos
function name:  callToPropertiesFromPublicContext
number of ops:  17
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   FETCH_OBJ_R                                      ~0      'publicVar'
          1        ECHO                                                     ~0
   52     2        FETCH_OBJ_R                                      ~1      'staticVar'
          3        ECHO                                                     ~1
   53     4        FETCH_THIS                                       ~2      
          5        FETCH_CLASS                                   0  $3      ~2
          6        FETCH_STATIC_PROP_R          unknown             ~4      'publicVar'
          7        ECHO                                                     ~4
   54     8        FETCH_THIS                                       ~5      
          9        FETCH_CLASS                                   0  $6      ~5
         10        FETCH_STATIC_PROP_R          unknown             ~7      'staticVar'
         11        ECHO                                                     ~7
   55    12        FETCH_STATIC_PROP_R          unknown             ~8      'publicVar'
         13        ECHO                                                     ~8
   56    14        FETCH_STATIC_PROP_R          unknown             ~9      'staticVar'
         15        ECHO                                                     ~9
   57    16      > 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/R2hos
function name:  callToPropertiesFromStaticContext
number of ops:  5
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   59     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'publicVar'
          1        ECHO                                                     ~0
   60     2        FETCH_STATIC_PROP_R          unknown             ~1      'staticVar'
          3        ECHO                                                     ~1
   61     4      > RETURN                                                   null

End of function calltopropertiesfromstaticcontext

End of class Descendant.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
172.78 ms | 1394 KiB | 13 Q