3v4l.org

run code in 300+ PHP versions simultaneously
<?php //this seems to work as if there is 2 variables both a public static and a private static class foo{ public static $myvar = 99; //Uncommenting below leads to a Cannot redeclare foo::$myvar //public $myvar = 77; public function __construct(){ $this->myvar = 35; } public function printMyVar(){ echo '->printMyVar(): '.$this->myvar; } public function setMyVar($mv){ $this->myvar = $mv; } } echo "foo before creation: \n"; echo 'static: foo::$myvar'.foo::$myvar."\n"; echo "Creating new instance of foo\n"; $foo = new foo(); echo 'instance: '.$foo->printMyVar(); echo "\n"; echo 'static foo::$myvar: '.foo::$myvar."\n"; $foo->setMyVar(33); echo "After setting $myvar to 33\n"; echo 'instance: '.$foo->printMyVar(); echo "\n"; echo 'static foo::$myvar: '.foo::$myvar."\n"; 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/lIZdc
function name:  (null)
number of ops:  36
compiled vars:  !0 = $foo, !1 = $myvar
line      #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   18     0  E >   ECHO                                                     'foo+before+creation%3A+%0A'
   19     1        FETCH_STATIC_PROP_R          unknown             ~2      'myvar'
          2        CONCAT                                           ~3      'static%3A+foo%3A%3A%24myvar', ~2
          3        CONCAT                                           ~4      ~3, '%0A'
          4        ECHO                                                     ~4
   22     5        ECHO                                                     'Creating+new+instance+of+foo%0A'
   23     6        NEW                                              $5      'foo'
          7        DO_FCALL                                      0          
          8        ASSIGN                                                   !0, $5
   25     9        INIT_METHOD_CALL                                         !0, 'printMyVar'
         10        DO_FCALL                                      0  $8      
         11        CONCAT                                           ~9      'instance%3A+', $8
         12        ECHO                                                     ~9
   26    13        ECHO                                                     '%0A'
   27    14        FETCH_STATIC_PROP_R          unknown             ~10     'myvar'
         15        CONCAT                                           ~11     'static+foo%3A%3A%24myvar%3A+', ~10
         16        CONCAT                                           ~12     ~11, '%0A'
         17        ECHO                                                     ~12
   30    18        INIT_METHOD_CALL                                         !0, 'setMyVar'
         19        SEND_VAL_EX                                              33
         20        DO_FCALL                                      0          
   31    21        ROPE_INIT                                     3  ~15     'After+setting+'
         22        ROPE_ADD                                      1  ~15     ~15, !1
         23        ROPE_END                                      2  ~14     ~15, '+to+33%0A'
         24        ECHO                                                     ~14
   32    25        INIT_METHOD_CALL                                         !0, 'printMyVar'
         26        DO_FCALL                                      0  $17     
         27        CONCAT                                           ~18     'instance%3A+', $17
         28        ECHO                                                     ~18
   33    29        ECHO                                                     '%0A'
   34    30        FETCH_STATIC_PROP_R          unknown             ~19     'myvar'
         31        CONCAT                                           ~20     'static+foo%3A%3A%24myvar%3A+', ~19
         32        CONCAT                                           ~21     ~20, '%0A'
         33        ECHO                                                     ~21
   37    34        ECHO                                                     'Conclusion%3A+when+using+%24this-%3E+to+change+the+value%2C+it+adds+another+non-static+version+rather+than+changing+the+static+version'
         35      > RETURN                                                   1

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

End of function __construct

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

End of function printmyvar

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

End of function setmyvar

End of class foo.

Generated using Vulcan Logic Dumper, using php 8.0.0


preferences:
155.34 ms | 1399 KiB | 13 Q