2013-06-02 60 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类型变量对我来说看起来不是特别静态的 –