【发布时间】:2018-01-24 06:18:52
【问题描述】:
我有一门课
class Foo
{
public function runWithCallback($custom_callback) {
...
return call_user_func_array($custom_callback, [$arg_a, $arg_b]);
}
public function aHelperMethod($arg_a) {
...
}
}
当我使用类时
$foo = new Foo();
$foo->runWithCallback(function($arg_a, $arg_b) {
...
// now I need to use helper method "aHelperMethod"
$this->aHelperMethod($arg_c); // wrong code
...
});
当然,上面的代码不起作用,因为$this 在那个匿名函数中毫无意义。
有可能做我想做的事吗?谢谢。
【问题讨论】:
-
你可以访问这样的功能
$foo->aHelperMethod() -
@BilalAhmed 谢谢,但我发现它有点“脏”。有没有更清洁的方法?