Is there a way how to execute closure in PHP5.3 within a context of an object?
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();
The eval() would work fine, however call_user_func will have no access to $this. (Using $this when not in object context). I am passing "$this" as an argument to closure right now, but that's not exactly what I need.