In my case, __invoke has come in handy when I wanted to transform the class autoloading process into an OOP one:
– I created a class that acts as an autoloader for a specific location where classes are stored.
– I can then pass this class to spl_autoload_register which takes a callable as first argument and will indeed be able to load a class upon request using the Autoload object provided.
Just to give you an idea of what I mean:
define(‘AUTOLOAD_PATH’, dirname(__FILE__).DIRECTORY_SEPARATOR);
define(‘AUTOLOAD_EXTENSION_SUFFIX’, ‘.php’);

class Autoload {
public static Autoload function register(string $base_path = null, string $path_suffix = null, bool $throw = true, bool $prepend = false);
public static bool function testPath(string $path);
public string function unify(string $class_name, string $base_path = null, string $path_suffix = null);
public mixed function __invoke(string $class_name);
}
To get back on __invoke, in this case Autoload::register will create a new Autoload object and pass it to spl_autoload_register and return Autoload object.