【发布时间】:2011-09-13 21:47:58
【问题描述】:
有没有办法将对象上下文传递给匿名函数将$this 作为参数传递?
class Foo {
function bar() {
$this->baz = 2;
# Fatal error: Using $this when not in object context
$echo_baz = function() { echo $this->baz; };
$echo_baz();
}
}
$f = new Foo();
$f->bar();
【问题讨论】:
标签: php scope anonymous-function