Question

I get the following error Parse error: syntax error, unexpected T_VARIABLE in path/queries.php on line 92

because of the array $_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 
                            );

Is there a problem with my way of filling $_queryArray ?

Thank you !

Was it helpful?

Solution

As $this references an instance, and doesn't exist when the class is being defined, you can't use $this in property definitions

Quoting from the 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.

OTHER TIPS

I assume the code is from within a class declaration.

My guess would be that you cannot access $this at this point. Try setting the array in the constructor.

function __construct() {
    $this->_queryArray = array( ... );
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top