靜態(tài)方法調(diào)用靜態(tài)變量的問題。。 return $speed+10;為什么錯的??一定要寫return self::$speed+=10;?
class Car {
? ? private static $speed = 10;? ??
? ? public function getSpeed() {
? ? ? ? return self::$speed;
? ? }??
? ? //在這里定義一個靜態(tài)方法,實現(xiàn)速度累加10
public static function speedUp(){
? ? return $speed+10;
}
}
$car = new Car();
Car::speedUp(); ?//調(diào)用靜態(tài)方法加速$speed+10
echo $car->getSpeed(); ?//調(diào)用共有方法輸出當前的速度值
2017-01-05
靜態(tài)變量是整個類的,靜態(tài)方法只能訪問靜態(tài)變量,只能使用self或static關鍵字訪問