2015-02-23 50 views
0

類屬性我有以下代碼:如何訪問方法

class FanClub_Banner 
{ 
    public $img = 'http://www.example.com/museum/images/logo_ver_250.png'; 

    public static function banner_me(array $widget, $positionCode, array $params, XenForo_Template_Abstract $renderTemplateObject) 
    { 
     return '<img src="'. $this->$img . '" width="250" height="250" alt="Museum">'; 
    } 
} 

和我得到的錯誤:

Fatal error: Using $this when not in object context in C:\public_html\comunidad\library\FanClub\Banner.php on line 8 

如何解決呢?

感謝

回答

1

您的靜態方法不能訪問你的類屬性,一個簡單的解決將是從public static function刪除static,並要使用這個方法,你會怎麼做FanClub_Banner fcBanner = new FanClub_Banner(); fcBanner->banner_me(....);

另一個解決將是使財產也是靜態的,所以你會有public static $img...