2013-07-20 59 views
0

我有這樣的功能:嚴格的標準:非靜態方法spController :: getLang()不應該被稱爲靜態

<?PHP 
function T($w) { 
    $method = $GLOBALS['G_SP']["lang"][spController::getLang()]; // LINE 2 
    if(!isset($method) || 'default' == $method){ 
     return $w; 
    }elseif(function_exists($method)){ 
     return ($tmp = call_user_func($method, $w)) ? $tmp : $w; 
    }elseif(is_array($method)){ 
     return ($tmp = spClass($method[0])->{$method[1]}($w)) ? $tmp : $w; 
    }elseif(file_exists($method)){ 
     $dict = require($method); 
     return isset($dict[$w]) ? $dict[$w] : $w; 
    }else{ 
     return $w; 
    } 
} 
?> 

不,我看到這個錯誤在第2行:

嚴格的標準:非靜態方法spController :: getLang()不應該 靜態用C稱爲:\ XAMPP \ htdocs中\ INC \ spFunctions.php第2行

如何解決這個錯誤?

注意:我需要解決這個問題,而不改變php.ini文件(禁止使用error_reporting = E_ALL | E_STRICT OR =的display_errors開,關)

+0

您是否驗證過您正在調用該方法?從錯誤看來,你應該有一個spController的實例,並從它調用getLang(),而不是將其稱爲靜態。 –

回答

2

如果spController::getLang()函數沒有引用實例屬性(使用$this),那麼您只需要將static添加到函數聲明中。即

public static function getLang(); 

,或者如果您使用的是參考$this,您將需要創建pController的一個實例,然後調用getLang()方法作爲實例方法。

$controller = new spController(); 
$lang = $controller->getLang(); 
0
$sp = new spController(); 
$sp->getLang(); 

又或許spController一個實例從somhere已經存在您的應用程序

相關問題