PHP __autoload function
When PHP encounters a class that hasn’t been defined yet, you can use __autoload to automatically add them instead of including masses of included at the top of your files. This was a lifesaver on older projects where every file had 20+ require_once statements at the top. The autoloader kicks in whenever you instantiate a class that hasn’t been loaded yet, and it pulls in the right file based on the class name.
Keep in mind that __autoload only supports a single autoload function. If you’re on PHP 5.1.2 or later, spl_autoload_register is the better choice since it lets you stack multiple autoloaders — useful when you’re mixing your own classes with third-party libraries.
e.g.
function __autoload($class_name) {
require_once $class_name . '.php';
}