課程
/后端開發(fā)
/PHP
/PHP進(jìn)階篇
這里面的self和this用法區(qū)別到底是什么???
2017-05-14
源自:PHP進(jìn)階篇 2-7
正在回答
private?static?$speed?=?10; public?$name='汽車'; public?function?getSpeed()?{ ??????return?self::$speed; ????} public?function?getName(){ ??????return?$this->name; ????}
self::$speed;靜態(tài)屬性用這個(gè)$this->name;普通屬性用這個(gè)this就是指向當(dāng)前對(duì)象實(shí)例的指針,不指向任何其他對(duì)象或類。self是指向類本身,也就是self是不指向任何已經(jīng)實(shí)例化的對(duì)象,一般self使用來指向類中的靜態(tài)變量。假如我們使用類里面靜態(tài)(一般用關(guān)鍵字static)的成員,我們也必須使用self來調(diào)用。還要注意使用self來調(diào)用靜態(tài)變量必須使用:: (域運(yùn)算符號(hào)),
?http://11463531.blog.hexun.com/81211052_d.html ? ? ?? ? ?
由于靜態(tài)方法不需要通過對(duì)象即可調(diào)用,所以偽變量 $this 在靜態(tài)方法中不可用
舉報(bào)
輕松學(xué)習(xí)PHP中級(jí)課程,進(jìn)行全面了解,用PHP快速開發(fā)網(wǎng)站程序
2 回答self和this什么區(qū)別?
3 回答self,parent,static有什么區(qū)別
4 回答self和parent的用法
2 回答PHP里面echo和print_r有什么區(qū)別?
2 回答speedUp方法里面為什么要用return self::$speed+=10;
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)
2017-06-03
self::$speed;靜態(tài)屬性用這個(gè)
$this->name;普通屬性用這個(gè)
this就是指向當(dāng)前對(duì)象實(shí)例的指針,不指向任何其他對(duì)象或類。
self是指向類本身,也就是self是不指向任何已經(jīng)實(shí)例化的對(duì)象,一般self使用來指向類中的靜態(tài)變量。假如我們使用類里面靜態(tài)(一般用關(guān)鍵字static)的成員,我們也必須使用self來調(diào)用。還要注意使用self來調(diào)用靜態(tài)變量必須使用:: (域運(yùn)算符號(hào)),
?http://11463531.blog.hexun.com/81211052_d.html ? ? ?
? ? ?