I have a class
class SomeClass {
private $someVar;
public function Init($func) {
$this->someVar = $func;
}
public function DoSomething() {
$this->someVar("asdasdasd");
}
}
$obj = new SomeClass();
$obj->Init(function ($param){var_dump($param);});
$obj->DoSomething();
When I call the method DoSomething, I get an error that SomeClass::someVar()
is undefined method. But when I use the debugger, I see that it is a closure object. If I save the function into a local variable ($someVar
without $this
) and call it in the Init()
function, it works just fine. But I don't want to call the function there. I want to call it later.
Even if I save it into $this->someVar
and call it in the same scope it does not work.