Using the PHP Function spl_autoload_functions
PHP supports a number of functions for loading classes and interfaces. However, most developers writing object oriented applications create one PHP source file per class definition and must include (via set_include_path()) a long list of needed includes at the beginning of each script. This is not only inconvenient but also slows down the execution of your application. Using the spl_autoload_functions function you can register autoloaders which allow you to skip these unnecessary include operations.
Unlike the __autoload() magic method which can only be called once spl_autoload_register() allows you to register multiple autoloaders. These autoloaders are loaded in the order they are registered and can be activated by calling spl_autoload(). This allows you to implement a very flexible solution for class loading in your application.
spl_autoload_register() accepts a callable as argument which is executed when the autoload stack is activated. This callable may return a closure or any other value. This value will be used to search for the required class or interface.
An optional parameter can be specified which allows you to specify a list of file extensions that the built in __autoload() fallback function will use to look for classes. If this parameter is not provided the default list of extensions is "