Monday, July 22, 2013

[PHP][OOP] 類別中使用靜態屬性

物件在實體化前,所有的屬性都是無法使用的,除了靜態屬性之外,未實體化也可以直些使用,直接看程式碼:(為了容易理解,我把class放上面)
class Test{   static $sta = 'a';   function get_sta(){     return self::$sta;   } } //方法一 echo Test::$sta; //方法二 $temp = new Test; echo $temp -> get_sta(); 備註:
如果使用echo $temp ->sta ;則會出現錯誤。

No comments:

Post a Comment