3v4l.org

run code in 300+ PHP versions simultaneously
<?php class foo{ public static $myvar = 99; 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::$myvar: '.foo::$myvar."\n"; $foo = new foo(); echo $foo->printMyVar(); echo "\n"; echo '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";
Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.20
Fatal error: Cannot redeclare foo::$myvar in /in/rMVg8 on line 5
Process exited with code 255.

preferences:
195.8 ms | 1395 KiB | 56 Q