A closer look at Invokable classes in PHP

1 · Amit Merchant · June 10, 2019, midnight
In PHP, Invokables refer to any class that may be instantiated without any constructor arguments. In other words, one should be able to create an instance solely be calling new $className(). To implement an invokable class, one needs to use __invoke() magic method of PHP. Before we understand how invokable exactly works, let’s take a look why invokable classes even exists in PHP. PHP does not allow the passing of function pointers like other languages. Functions are not first class in PHP. Funct...