This question already has an answer here:
I have code like this:
class Foo {
var $callbacks = array();
function __construct() {
$this->callbacks[] = function($arg) {
return $this->bar($arg);
};
}
function bar($arg) {
return $arg * $arg;
}
}
and I would like to use $this inside closures, I've try to add use ($this)
but this throw error:
Cannot use $this as lexical variable
</div>