All anonymous functions are in fact an instance of the Closure
class. However, as stated in the documentation (http://php.net/manual/en/class.closure.php), this class does not use the aforementioned __invoke
method; it's a special case in the PHP interpreter:
Besides the methods listed here, this class also has an __invoke method. This is for consistency with other classes that implement calling magic, as this method is not used for calling the function.
This method on the class allows you to change to which object the $this
variable will be bound inside the closure. You can even bind an object to a closure created outside of the class.
If you start using the features of the Closure
class, keep in mind that the call
method was just recently added in PHP 7.