Using the PHP Function spl_autoload_unregister
In PHP, we can incorporate classes defined in other scripts with include or require statements. But autoloading is a way to do this without the need for any explicit inclusion. When a class is used in PHP, the parser will try to load it automatically from its corresponding file path (if it has been registered).
This works great if you use relative paths and don't mind lower-casing your file names because it's very efficient. But it's not that useful within a framework where multiple people are writing their own components.
Luckily, there's a solution for this: the spl_autoload_unregister function. This allows us to register a callback function for each class that we need to load. Then, when the class is instantiated, it will execute all of the registered functions in order until one finds the correct file.
The problem with this approach is that it can result in "__PHP_Incomplete_Class_Name" errors if the unserialized class has methods from an as-yet-unloaded static class. This can be prevented by making sure the spl_autoload_register() is done BEFORE session_start() is called.
To do this, simply pass 'no params' to spl_autoload_register(). This will cause it to prepend the autoloader on the stack rather than appending it.