課程
/后端開發
/PHP
/PHP進階篇
public function speedUp() {
? ? ? ? $this->speed += 10;
? ? }為什么speed不加$了,這樣不是變量啊,不理解
2017-03-24
源自:PHP進階篇 2-4
正在回答
//?因為我們訪問的是類的屬性 //?在PHP中訪問類的屬性可以用->操作符來訪問
如果前面定義 $speed = 'hehe';
如果加$ ??$this->speed 不就成了$this->hehe?
$this->speed=$this->speed+10;可以這樣寫,就是說$this->speed這個整體是一個變量,大白話可以理解為就這個方法里邊的那個speed
$this就是this加上$偽變量了,然后調用speed。
舉報
輕松學習PHP中級課程,進行全面了解,用PHP快速開發網站程序
5 回答class Truck extends Car{ public function speedUp(){ $this->speed=parent::speedUp()+50; } }
1 回答為什么要用$this->speed,不用$speed?
1 回答$this->speed -=10;
7 回答$this->speed += 10; 這個+=是什么意思啊
2 回答$car->speed,為什么不是$car->$speed?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2017-07-01
2017-05-10
如果前面定義 $speed = 'hehe';
如果加$ ??$this->speed 不就成了$this->hehe?
2017-04-23
$this->speed=$this->speed+10;可以這樣寫,就是說$this->speed這個整體是一個變量,大白話可以理解為就這個方法里邊的那個speed
2017-03-24
$this就是this加上$偽變量了,然后調用speed。