課程
/后端開發(fā)
/PHP
/PHP進(jìn)階篇
class Car {
? ? public $speed = 10;
? ? //增加speedUp方法,使speed加10
? ? ? function speedUp() {
? ? ? ? return ($speed+=100);
? ? }
}
$car = new Car();
echo $car->speedUp();
輸出的結(jié)果是100
2015-10-13
源自:PHP進(jìn)階篇 2-4
正在回答
<?php class?Car?{ ????public?$speed?=?10; ????//增加speedUp方法,使speed加10 ??????function?speedUp()?{ ????????return?($this->speed+=100); ????} } $car?=?new?Car(); echo?$car->speedUp();
fishfishmanman 提問(wèn)者
gaode buchou
zby5241
zby5241 回復(fù) zby5241
舉報(bào)
輕松學(xué)習(xí)PHP中級(jí)課程,進(jìn)行全面了解,用PHP快速開發(fā)網(wǎng)站程序
2 回答speedUp方法里面為什么要用return self::$speed+=10;
1 回答靜態(tài)方法調(diào)用靜態(tài)變量的問(wèn)題。。 return $speed+10;為什么錯(cuò)的??一定要寫return self::$speed+=10;?
3 回答為什么是return $this->name; 而不是return $this->$name;
1 回答為什么要使用speedUp方法,直接public $speed = 0(想要的值);不行嗎?
3 回答請(qǐng)問(wèn)【return self:: $speedUp = $speedUp + 10; return self::$speed+=10;】這兩個(gè)表達(dá)方式有什么區(qū)別呀?為什么結(jié)果不同?
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購(gòu)課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2015-10-13
2015-10-13
gaode buchou