2010-07-25 42 views
0

靜態變量我有類的簡單的情況下,靜態變量和get函數 所有編譯好,但在運行時我收到此錯誤accesing在PHP

[Sun Jul 25 03:57:07 2010] [error] [client 127.0.0.1] PHP Fatal error: Undefined class constant 'TYPE' in ..... 

爲函數的getType()

這裏是我的類

class NoSuchRequestHandler implements Handler{ 
    public static $TYPE = 2001; 
    public static $VER = 0; 

    public function getType(){ 
     return self::TYPE; 
    } 

    public function getVersion(){ 
     return self::VER; 
    } 
} 

謝謝大家

回答

3

您可以訪問此兩種方式,因爲它是公共...

class NoSuchRequestHandler implements Handler{ 
    public static $TYPE = 2001; 
    public static $VER = 0; 

    public function getType(){ 
     return self::$TYPE; //not the "$" you were missing. 
    } 

    public function getVersion(){ 
     return self::$VER; 
    } 
} 

echo NoSuchRequestHandler::$TYPE; //outside of the class. 
+0

非常感謝你 – shay 2010-07-25 01:16:50

+0

修復格式,我會很樂意爲+1 nswer。 – 2010-07-25 01:18:38

+0

你去@GeorgeMarian;) – 2012-10-11 07:52:09