Before we look at specific solutions, we can explore various helpful aspects of PHP and also look at the pattern known as Singleton.
We want to automate the loading of code and PHP provided a tool to do exactly this with the launch of PHP5. It was the
__autoload function. When PHP came across a class it did not know about, it called
__autoload, passing the class name as parameter. It was up to the user to code a suitable body for the function.
This was a good start, and in the first edition it was the solution to the problem. However, PHP has moved on and improved the handling of autoloading. The obvious problem with
__autoload was that there could only be one such function. Someone writing, ...