当我在create_function
中使用$this
时,我得到一个错误
致命错误:不在对象上下文中时使用$this
create_function('$model, $this', 'return $this->di->getStatus($model->getStatus)');
后来我把它叫做
$function($model, $this);
我向函数传递了$this
,但似乎不起作用。有办法绕过它吗?
感谢
经过数小时的调试和研究,我发现我的代码被封装在一个函数中,所以最终的结果类似于
function($var1, $var2) { return create_function()}
通过这种方式创建了一个闭包,$this
不再在我想要的范围内。
更多关于闭包的信息,请点击此处:http://php.net/manual/ro/class.closure.php