在数组中使用函数时出现分析错误
我试图创建一个函数数组。虽然,执行此代码在数组中使用函数时出现分析错误
protected $filter_functions = [
"price" => function(&$query, $lower, $higher) {
$query->where("price", ">=", $lower)->where("price", "<=", $higher);
}
];
当我越来越parse error
,仅此而已,我不能看到任何语法错误,但也许有。 PHP版本目前是5.6.28,应该与匿名函数兼容。
你必须你使用Yii投入构造
protected $filter_functions;
public function __construct(){
$this->filter_functions = [
"price" => function(&$query, $lower, $higher) {
$query->where("price", ">=", $lower)->where("price", "<=", $higher);
}
];
}
'__constructor'应该最有可能读为'__construct'。除非Laravel使用'__constructor'。编辑:这个评论按照原始http://*.com/revisions/42370244/1 –
https://laravel.com/docs/5.0/controllers它使用'__construct'好吧。 –
我想在你尝试设置'$ this-> filter_functions'之前,你还需要'parent :: __ construct();',但我不是100%。 –
呢? – Sakezzz
不,Laravel框架 –
我向标签添加了该信息。谢谢 –