I want to access the $a
object method myMethod() with all $a
object's properties inside overriden function. How can I do it? Thanks a lot for your help .
$a = new A('property');
$a->testFunc = Closure::bind(function() {
// here the object scope was gone...
$a->myMethod();
$this->var = "overridden";
}, $a);
You can use the use
keyword when defining your function like this:
$a = new A('property');
$a->testFunc = Closure::bind(function() use ($a) {
// here the object scope was gone...
$a->myMethod();
$this->var = "overridden";
}, $a);
This will tell php to include $a
as part of your function's scope.