Risolvere “Using $this when not in object context” in closure
Cosa ho imparato oggi: come risolvere l’errore “Using $this when not in object context” quando si lavora con una closure.
E’ semplice, si usa il metodo bindTo() della closure:
if (is_callable($closure)) { $closure = $closure->bindTo($this, $this); $closure(); // Call your closure as you wish! }