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 "this is ancestor's public method\n"; // is $this is set up if(isset($this)){ echo "publicMethod is in object context\n"; }else{ echo "publicMethod is in static context\n"; } } static function staticMethod(){ echo "this is ancestor's static method\n"; // is $this is set up if(isset($this)){ echo "staticMethod is in object context\n"; }else{ echo "staticMethod is 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 "this is descendant's public method\n"; // is $this is set up if(isset($this)){ echo "publicMethod is in object context\n"; }else{ echo "publicMethod is in static context\n"; } } static function staticMethod(){ echo "this is descendant's static method\n"; // is $this is set up if(isset($this)){ echo "staticMethod is in object context\n"; }else{ echo "staticMethod is in static context\n"; } } } $ancestor = new Ancestor(); $descendant = new Descendant(); // From Outside Of An Instance/Class: // access to properties echo $descendant->publicVar; // descendant's public var echo $descendant->staticVar; // "" + notice: Undefined property: Descendant::$staticVar echo $descendant::$staticVar; // descendant's static var //echo $descendant::$publicVar; // fatal error: Access to undeclared static property: Descendant::$publicVar //echo Ancestor::$publicVar; // fatal error: Access to undeclared static property echo Ancestor::$staticVar; //ancestor's static var //echo Descendant::$publicVar; // fatal error: Access to undeclared static property echo Descendant::$staticVar; // descendant's static var // access to methods $descendant->publicMethod(); $descendant->staticMethod(); $descendant::staticMethod(); $descendant::publicMethod(); //Ancestor::publicMethod();
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/l8Gj2
function name:  (null)
number of ops:  28
compiled vars:  !0 = $ancestor, !1 = $descendant
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   51     0  E >   NEW                                              $2      'Ancestor'
          1        DO_FCALL                                      0          
          2        ASSIGN                                                   !0, $2
   52     3        NEW                                              $5      'Descendant'
          4        DO_FCALL                                      0          
          5        ASSIGN                                                   !1, $5
   56     6        FETCH_OBJ_R                                      ~8      !1, 'publicVar'
          7        ECHO                                                     ~8
   57     8        FETCH_OBJ_R                                      ~9      !1, 'staticVar'
          9        ECHO                                                     ~9
   58    10        FETCH_CLASS                                   0  $10     !1
         11        FETCH_STATIC_PROP_R          unknown             ~11     'staticVar'
         12        ECHO                                                     ~11
   62    13        FETCH_STATIC_PROP_R          unknown             ~12     'staticVar'
         14        ECHO                                                     ~12
   64    15        FETCH_STATIC_PROP_R          unknown             ~13     'staticVar'
         16        ECHO                                                     ~13
   67    17        INIT_METHOD_CALL                                         !1, 'publicMethod'
         18        DO_FCALL                                      0          
   68    19        INIT_METHOD_CALL                                         !1, 'staticMethod'
         20        DO_FCALL                                      0          
   69    21        FETCH_CLASS                                   0  $16     !1
         22        INIT_STATIC_METHOD_CALL                                  $16, 'staticMethod'
         23        DO_FCALL                                      0          
   70    24        FETCH_CLASS                                   0  $18     !1
         25        INIT_STATIC_METHOD_CALL                                  $18, 'publicMethod'
         26        DO_FCALL                                      0          
   72    27      > 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/l8Gj2
function name:  publicMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
    6     0  E >   ECHO                                                     'this+is+ancestor%27s+public+method%0A'
    8     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
    9     3    >   ECHO                                                     'publicMethod+is+in+object+context%0A'
          4      > JMP                                                      ->6
   11     5    >   ECHO                                                     'publicMethod+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/l8Gj2
function name:  staticMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   ECHO                                                     'this+is+ancestor%27s+static+method%0A'
   18     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   19     3    >   ECHO                                                     'staticMethod+is+in+object+context%0A'
          4      > JMP                                                      ->6
   21     5    >   ECHO                                                     'staticMethod+is+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/l8Gj2
function name:  publicMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     'this+is+descendant%27s+public+method%0A'
   33     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   34     3    >   ECHO                                                     'publicMethod+is+in+object+context%0A'
          4      > JMP                                                      ->6
   36     5    >   ECHO                                                     'publicMethod+is+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/l8Gj2
function name:  staticMethod
number of ops:  7
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   41     0  E >   ECHO                                                     'this+is+descendant%27s+static+method%0A'
   43     1        ISSET_ISEMPTY_THIS                               ~0      
          2      > JMPZ                                                     ~0, ->5
   44     3    >   ECHO                                                     'staticMethod+is+in+object+context%0A'
          4      > JMP                                                      ->6
   46     5    >   ECHO                                                     'staticMethod+is+in+static+context%0A'
   48     6    > > RETURN                                                   null

End of function staticmethod

End of class Descendant.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
164.77 ms | 1399 KiB | 13 Q