為什么會(huì)報(bào)錯(cuò)?
class Car {
? ? public $speed = 0;
? ? //增加speedUp方法,使speed加10
? ? public static function speedUp(){
? ? ? ? $this->speed+=10;
? ? }
}
$car = new Car();
Car::speedUp();
echo $car->speed;
class Car {
? ? public $speed = 0;
? ? //增加speedUp方法,使speed加10
? ? public static function speedUp(){
? ? ? ? $this->speed+=10;
? ? }
}
$car = new Car();
Car::speedUp();
echo $car->speed;
2017-11-25
舉報(bào)
2020-03-29
使用靜態(tài)方法 不需要new
2017-12-14
在PHP里,有static修飾的變量和函數(shù)不能出現(xiàn)$this。
2017-11-26
愛學(xué)習(xí)的大佬,我關(guān)注一下,對(duì)象和類啥的我也不懂