- Output for 5.3.0 - 5.3.27, 5.4.0 - 5.4.20
- Fatal error: Cannot redeclare foo::$myvar in /in/68J5R on line 5
Process exited with code 255.
<?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 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";