-1

当我在$this里面使用时create_function出现错误

致命错误:不在对象上下文中使用 $this

create_function('$model, $this', 'return $this->di->getStatus($model->getStatus)');

后来我称之为

$function($model, $this);

我传递$this给该函数,但似乎不起作用。有办法绕过它吗?

谢谢

4

1 回答 1

0

经过数小时的调试和研究,我发现我的代码被包装在一个函数中,所以最终结果类似于

function($var1, $var2) { return create_function()}

这样就创建了一个闭包,并且$this不再在我想要的范围内。

更多关于这里的闭包:http: //php.net/manual/ro/class.closure.php

于 2016-04-03T17:53:43.633 回答