2013-06-02 111 views
-2

時意外T_VARIABLE我收到以下錯誤解析錯誤:語法錯誤,在路徑 /queries.php意外T_VARIABLE上,因爲陣列$_queryArray線92PHP:初始化關聯數組

private $_queryA = ""; 
etc... 
private $_queryV = ""; 


private $_queryArray = array( 'A' => $this->_queryA, //<= line 92 of my code 
           'B' => $this->_queryB, 
           'C' => $this->_queryC, 
           'D' => $this->_queryD, 
           'E' => $this->_queryE, 
           'F' => $this->_queryF, 
           'G' => $this->_queryG, 
           'H' => $this->_queryH, 
           'I' => $this->_queryI, 
           'J' => $this->_queryJ, 
           'K' => $this->_queryK, 
           'L' => $this->_queryL, 
           'M' => $this->_queryM, 
           'N' => $this->_queryN, 
           'O' => $this->_queryO, 
           'P' => $this->_queryP, 
           'Q' => $this->_queryQ, 
           'R' => $this->_queryR, 
           'S' => $this->_queryS, 
           'T' => $this->_queryT, 
           'U' => $this->_queryU, 
           'V' => $this->_queryV 
          ); 

我的填充方式有問題嗎$_queryArray ?

謝謝!

回答

2

通過$ this引用一個實例,併爲正在定義的類時不存在,則不能使用$這在屬性定義

docs

This declaration may include an initialization, but this initialization must be a constant value--that is, it must be able to be evaluated at compile time and must not depend on run-time information in order to be evaluated.

+0

使它成爲一個空數組,並在構造函數中填充它,當你構建查詢時 –

+0

更好,然後改爲getter函數。 –

1

我假設代碼來自類聲明。

我的猜測是,您現在無法訪問$ this。 嘗試在構造函數中設置數組。

function __construct() { 
    $this->_queryArray = array(...); 
} 
+0

報價看起來,這仍然過於本土化。 – vascowhite

+0

我可以做到這一點,但我在將它們放入數組之前以靜態方式填充查詢。構造函數有200行靜態填充no:s會非常難看? –

+0

那些$ _query_A類型變量對我來說看起來不是特別靜態的 –