3v4l.org

run code in 300+ PHP versions simultaneously
<?php //this seems to work as if there is 2 variables both a protected static and a protected non-static class foo { protected static $myvar = 999; //Uncommenting below leads to a Cannot redeclare foo::$myvar //public $myvar = 77; //Normal non-static Instance Functions public function __construct(){} public function instancePrintVar(){ echo __FUNCTION__.' '.$this->myvar; } public function instanceSetVar($v){ $this->myvar = $mv; } //Static functions public static function staticPrintVar(){ echo __FUNCTION__.' '.self::$myvar; } public static function staticSetVar($v){ self::$myvar = $v; } } function nl(){ echo "\n"; } foo::staticPrintVar(); nl(); $foo = new foo(); $foo->instanceSetVar(3); $foo->instancePrintVar(); nl(); foo::staticPrintVar(); nl(); $foo::staticPrintVar(); nl(); echo "Conclusion: when using \$this-> to change the value, it adds another non-static version rather than changing the static version";
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  (null)
number of ops:  25
compiled vars:  !0 = $foo
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   33     0  E >   INIT_STATIC_METHOD_CALL                                  'foo', 'staticPrintVar'
          1        DO_FCALL                                      0          
   34     2        INIT_FCALL                                               'nl'
          3        DO_FCALL                                      0          
   36     4        NEW                                              $3      'foo'
          5        DO_FCALL                                      0          
          6        ASSIGN                                                   !0, $3
   37     7        INIT_METHOD_CALL                                         !0, 'instanceSetVar'
          8        SEND_VAL_EX                                              3
          9        DO_FCALL                                      0          
   38    10        INIT_METHOD_CALL                                         !0, 'instancePrintVar'
         11        DO_FCALL                                      0          
   39    12        INIT_FCALL                                               'nl'
         13        DO_FCALL                                      0          
   41    14        INIT_STATIC_METHOD_CALL                                  'foo', 'staticPrintVar'
         15        DO_FCALL                                      0          
         16        INIT_FCALL                                               'nl'
         17        DO_FCALL                                      0          
   42    18        FETCH_CLASS                                   0  $11     !0
         19        INIT_STATIC_METHOD_CALL                                  $11, 'staticPrintVar'
         20        DO_FCALL                                      0          
         21        INIT_FCALL                                               'nl'
         22        DO_FCALL                                      0          
   46    23        ECHO                                                     'Conclusion%3A+when+using+%24this-%3E+to+change+the+value%2C+it+adds+another+non-static+version+rather+than+changing+the+static+version'
         24      > RETURN                                                   1

Function nl:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  nl
number of ops:  2
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   31     0  E >   ECHO                                                     '%0A'
          1      > RETURN                                                   null

End of function nl

Class foo:
Function __construct:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  __construct
number of ops:  1
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   11     0  E > > RETURN                                                   null

End of function __construct

Function instanceprintvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  instancePrintVar
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   14     0  E >   FETCH_OBJ_R                                      ~0      'myvar'
          1        CONCAT                                           ~1      'instancePrintVar+', ~0
          2        ECHO                                                     ~1
   15     3      > RETURN                                                   null

End of function instanceprintvar

Function instancesetvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  instanceSetVar
number of ops:  4
compiled vars:  !0 = $v, !1 = $mv
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   16     0  E >   RECV                                             !0      
   17     1        ASSIGN_OBJ                                               'myvar'
          2        OP_DATA                                                  !1
   18     3      > RETURN                                                   null

End of function instancesetvar

Function staticprintvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  staticPrintVar
number of ops:  4
compiled vars:  none
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   23     0  E >   FETCH_STATIC_PROP_R          unknown             ~0      'myvar'
          1        CONCAT                                           ~1      'staticPrintVar+', ~0
          2        ECHO                                                     ~1
   24     3      > RETURN                                                   null

End of function staticprintvar

Function staticsetvar:
Finding entry points
Branch analysis from position: 0
1 jumps found. (Code = 62) Position 1 = -2
filename:       /in/QslAJ
function name:  staticSetVar
number of ops:  4
compiled vars:  !0 = $v
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   26     0  E >   RECV                                             !0      
   27     1        ASSIGN_STATIC_PROP                                       'myvar'
          2        OP_DATA                                                  !0
   28     3      > RETURN                                                   null

End of function staticsetvar

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
152.05 ms | 1403 KiB | 17 Q