課程
/后端開發
/PHP
/PHP進階篇
class Car {
? ? public $speed = 10;
? ? //增加speedUp方法,使speed加10
? ? ? function speedUp() {
? ? ? ? return ($speed+=100);
? ? }
}
$car = new Car();
echo $car->speedUp();
輸出的結果是100
2015-10-13
源自:PHP進階篇 2-4
正在回答
<?php class?Car?{ ????public?$speed?=?10; ????//增加speedUp方法,使speed加10 ??????function?speedUp()?{ ????????return?($this->speed+=100); ????} } $car?=?new?Car(); echo?$car->speedUp();
fishfishmanman 提問者
gaode buchou
zby5241
zby5241 回復 zby5241
舉報
輕松學習PHP中級課程,進行全面了解,用PHP快速開發網站程序
2 回答speedUp方法里面為什么要用return self::$speed+=10;
1 回答靜態方法調用靜態變量的問題。。 return $speed+10;為什么錯的??一定要寫return self::$speed+=10;?
3 回答為什么是return $this->name; 而不是return $this->$name;
3 回答為什么有的有return,有的沒有
3 回答請問【return self:: $speedUp = $speedUp + 10; return self::$speed+=10;】這兩個表達方式有什么區別呀?為什么結果不同?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-10-13
2015-10-13
gaode buchou