2010-09-02 96 views
1

我試圖定義它,當一個值賦給一個靜態類屬性:Zend和靜態類屬性

namespace Base; 

abstract class Skeleton { 

protected static $entityManager = \Zend_Registry::get("EntityManager"); 
    ... 
} 

當我嘗試執行此代碼,我得到這個錯誤:

Parse error: syntax error, unexpected '(', expecting ',' or ';' in /var/www/ 
somewhere/application/models/Base/Skeleton.php on line 6 

如果我只是給它分配一個簡單的字符串值:

protected static $entityManager = "string"; 

沒有問題。我在做PHP不能處理的事情嗎?如果是這樣,如何解決這個問題?

回答

3

你不能把需要執行的代碼作爲一個類變量,是否爲靜態的。

想一想,Zend_Registry::get("EntityManager")在哪一點被執行,當創建類時因爲已將其設置爲static而無法執行。

即使它不是靜態的,Zend_Registry::get("EntityManager")何時運行?當對象被實例化或一次?它需要放在課堂上的一個功能。