我正在尝试在类中设置一个public/private
(无关紧要)变量(数组)
以这种方式(非常剥离)
class Test extends Whatever
{
private $rules = array(
'folder' => 'files/game/pictures/' . date('Ymd'), //this line causes error mentioned below
);
public function __construct() {//some code}
}
它给了我一个错误
Parse error: syntax error, unexpected '.', expecting ')'
为什么?我一直声明这样的数组,没有问题。
解决方案 :问题下方的第一条评论。
请尝试:
class Test extends Whatever {
private $rules;
public function __construct() {
$this->rules = array(
'folder' => 'files/game/pictures/' . date('Ymd'), //this line causes error mentioned below
);
}
}
类声明的变量不使用数组(它是一个对象)。试试这个:
class Test extends Whatever {
private $rules = array();
public function __construct() {
$this->rules = array('folder' => 'files/game/pictures/' . date('Ymd'));
// Other code...
}
}