self不能用于訪問類自身的屬性這句話該怎么理解???
self不能用于訪問類自身的屬性這句話該怎么理解???
1 <?php
? 2 class Child{
? 3 ? ? public static $value='static value';
? 4 ? ? public function test(){
? 5 ? ? ? ? echo self::$value;
? 6 ? ? }?
? 7 }
? 8 $obj= new Child();
? 9 $obj->test();
?10 ?>
我寫了小的程序試了下 ,$value作為類Child的屬性,完全可以輸出 static value ? ?
2015-01-14
self可以用于輸出自身類的靜態(tài)屬性,不能輸出自身類的非靜態(tài)屬性。你輸出的$value是靜態(tài)屬性,如果把static去掉,就不能用self來輸出了
2018-01-03
其實(shí)講解的老師表達(dá)的意思應(yīng)該是“自身的非靜態(tài)屬性”。
注意區(qū)分this self static parent
this self static用于類自身數(shù)據(jù)訪問,parent用于父類數(shù)據(jù)訪問
對于屬性,this可以訪問非靜態(tài)屬性,self static?parent用于靜態(tài)屬性。
對于方法,this self parent可以訪問靜態(tài)、非靜態(tài)方法,static可以訪問靜態(tài)方法。
2016-04-11
我也是對這句話理解有問題.
2016-01-22
應(yīng)該再加一個(gè) this偽變量作為對比 就比較容易理解了, this用于訪問自身非靜態(tài)屬性 self用戶訪問靜態(tài)屬性
2014-12-17
對于這句話,理解不能。