Php 在数组中使用函数时出现分析错误

Php 在数组中使用函数时出现分析错误,php,arrays,laravel-5,anonymous-function,Php,Arrays,Laravel 5,Anonymous Function,我正在尝试创建一个函数数组。尽管如此,在执行此代码时,我得到了解析错误,除此之外什么都没有 protected $filter_functions = [ "price" => function(&$query, $lower, $higher) { $query->where("price", ">=", $lower)->where("price", "<=", $higher); } ]; 受保护的$filter\u函

我正在尝试创建一个函数数组。尽管如此,在执行此代码时,我得到了
解析错误
,除此之外什么都没有

protected $filter_functions = [
    "price" => function(&$query, $lower, $higher) {
        $query->where("price", ">=", $lower)->where("price", "<=", $higher);
    }
];
受保护的$filter\u函数=[
“价格”=>功能(&$query、$lower、$higher){

$query->where(“price”,“>=”,$lower)->where(“price”,“您必须将其放入构造函数中

protected $filter_functions;

public function __construct(){
    $this->filter_functions = [
        "price" => function(&$query, $lower, $higher) {
            $query->where("price", ">=", $lower)->where("price", "<=", $higher);
        }
    ];
}
受保护的$filter\u函数;
公共函数构造(){
$this->filter_函数=[
“价格”=>功能(&$query、$lower、$higher){

$query->where(“价格”、“>=”、$lower)->where(“价格”、”您使用的是yii吗?不,Laravel Framework我将该信息添加到标记中。谢谢您,日志如何;是否存在更具描述性的错误?您可能希望将此声明移动到构造函数或其他地方,因为在声明类属性时无法执行php代码
\u构造函数
,该类属性很可能被理解为
\u construct
。除非Laravel使用
\u构造函数
。编辑:此注释与原始注释相同,它使用
\u构造函数
好的。我认为您还需要有
父项::\u构造函数()
在您尝试设置
$this->filter_函数之前,但我不是100%同意。仅当您从另一个类扩展此类,但根据给定示例,这一点不清楚时