2009-09-19 133 views
0

我在PHP中,我必須訪問一個名稱必須更改的對象的Static方法。PHP自定義靜態方法訪問

private $controlleur = null; 
    private static $instance = null; 

    private function __construct() { 
    $nomControlleur = "Controlleurs\_" . Session::singleton()->controlleur; 
    $this->controlleur = $nomControlleur::singleton(); 
    } 

這段代碼給了我「Syntax error unexpected ::」。我也試過寫{$ nomControlleur} :: singleton();但它給了我更多的錯誤, 非常感謝您的幫助。

球鋼

回答

2

用途:

$this->controlleur = call_user_func(array($nomControlleur, 'singleton')); 

或(僅5.2.3+)

$this->controlleur = call_user_func($nomControlleur . '::singleton'); 
0

什麼

$staticCall = $nonController."::singleton()"; 
$staticCall(); 

+0

非常感謝,但我已經找到了您的意見。只需拉單()中的(),因爲當你調用它時,它會給出singleton()(); – malavv 2009-09-19 20:08:59