I have the following in a class.
class My_Class {
$x = 'happy';
$y = array( 'iam' => $this->x);
//getting a 500 error with that.
function __construct() {
// scripts, etc
}
}
I get an unexpected $this (T_VARIABLE). Any thoughts?
You can't use $this when defining the instance variables. Try this alternative:
class My_Class {
var $x = 'happy';
var $y = array();
function __construct() {
$this->y['iam'] = $this->x;
}
}
You cannot put a variable in the class definition. Constants work, but anything else (concatenation, etc) will throw an error.