-2

我收到以下错误 Parse error: syntax error, unexpected T_VARIABLE in path /queries.php on line 92

因为数组$_queryArray

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 ?

谢谢 !

4

2 回答 2

2

由于 $this 引用了一个实例,并且在定义类时不存在,因此您不能在属性定义中使用 $this

文档中引用

这个声明可能包括一个初始化,但是这个初始化必须是一个常量值——也就是说,它必须能够在编译时被评估,并且不能依赖于运行时信息才能被评估。

于 2013-06-02T17:00:34.850 回答
1

我假设代码来自类声明。

我的猜测是您此时无法访问 $this 。尝试在构造函数中设置数组。

function __construct() {
    $this->_queryArray = array( ... );
}
于 2013-06-02T16:59:49.467 回答