靜態(tài)方法中可以調(diào)用非靜態(tài)屬性么?
class Car {
? ? private static $speed = 10; ??
????public $name = '汽車';//這里多了一個共有屬性
? ? public function getSpeed() {
? ? ? ? return self::$speed;
? ? } ??
? ? //在這里定義一個靜態(tài)方法,實(shí)現(xiàn)速度累加10
? ? public static function speedUp(){
????????//這里能調(diào)用上面共有屬性name么
? ? ? ? return self::$speed += 10; ??
? ? }
}
比如這個案例,我在里面添加一個共有屬性$name,我在靜態(tài)方法中能調(diào)用這個共有屬性么,如果可以,怎么調(diào)用?
2016-12-02
public static function speedUp(){
????$car = new Car();
??? echo $car->name;
????return self::$speed += 10;
}
這樣不就調(diào)用了$name
2016-12-02
$this->name?
2016-12-02
肯定可以