代码解释得更好:
class Class{ $var = 0; function getvar() echo $this->var; } } $inst1 = new Class(); // I want to change $var here to 5 $inst2 = new Class(); echo $inst2->getvar(); // should be 5
可能吗
静态的.
http://php.net/manual/en/language.oop5.static.php
class MyClass { public static $var = 0; function setVar($value) { self::$var = $value; } function getVar() { return self::$var; } } echo MyClass::$var; MyClass::setVar(1); echo MyClass::getVar(); //Outputs 1