The Invoke Magic Method In PHP
I discovered a good use case of __invoke – that’s when a function expects a callable, e.g. spl_autoload_register.
In this case we often see implementation passes an anonymous function or a named function.
We can also craft a class which implements __invoke. It’s not too awkward to use.
Let’s compare these three methods.
The paragraphs above merely point out a fact that there is a third option when we implement a callable.
Yet this becomes interesting when you want to dynamically generate a callable for the function that expects a callable, e.g. spl_autoload_register.
That’s all!