有没有办法如何在对象的上下文中执行PHP5.3中的闭包?
class Test {
public $name='John';
function greet(){
eval('echo "Hello, ".$this->name;');
call_user_func(function(){
echo "Goodbye, ".$this->name;
});
}
}
$c = new Test;
$c->greet();
Run Code Online (Sandbox Code Playgroud)
eval()可以正常工作,但是call_user_func将无法访问$ this.(在不在对象上下文中时使用$ this).我现在正在通过"$ this"作为关闭的论据,但这并不是我所需要的.
php ×1