You can read about the PHP autoloading on the php website. Using the autoloader allows us to lazily load classes as they are requested instead of pre-loading all classes. This is a huge benefit to performance.
The way the Doctrine autoloader works is simple. Because our class names and paths are related, we can determine the path to a Doctrine class based on its name.
Imagine we have a class named Doctrine_Some_Class and we instantiate an instance of it:
$class = new Doctrine_Some_Class();
The above code will trigger a call to the Doctrine_Core::autoload() function and pass it the name of the class instantiated. The class name string is manipulated and transformed in to a path and required. Below is some pseudo code that shows how the class is found and required:
class Doctrine
{
public function autoload($className)
{
$classPath = str_replace('_', '/', $className) . '.php';
$path = '/path/to/doctrine/' . $classPath;
require_once($path);
return true;
}
}
In the above example the Doctrine_Some_Class can be found at /path/to/doctrine/Doctrine/Some/Class.php.
Obviously the real Doctrine_Core::autoload() function is a bit more complex and has some error checking to ensure the file exists but the above code demonstrates how it works.