In this step, we will set up automatic class loading. After this, when we need a class file, we will not need an include or require statement to load it for us. You should review the PHP documentation on autoloaders before continuing – http://www.php.net/manual/en/language.oop5.autoload.php.

There are many different autoloader recommendations in PHP land. The one we will be using to modernize our legacy application is based on something called PSR-0.

PSR-0 is a PHP Framework Interoperability Group recommendation for structuring your class files. The recommendation rises out of a long history of projects using the "class-to-file" naming convention from the days of PHP 4. Originating with Horde and PEAR, the convention was adopted by early PHP 5 projects such as Solar and Zend Framework, and later by projects such as Symfony2.

We use PSR-0 instead of the newer PSR-4 recommendation because we are dealing with legacy code, code that was probably developed before PHP 5.3 namespaces came into being. Code written before PHP 5.3 did not have access to namespace separators, so authors following the class-to-file naming convention would typically use underscores in class names as a pseudo-namespace separator. PSR-0 makes an allowance for older non-PHP-5.3 pseudo-namespaces, making it more suitable for our legacy needs, whereas PSR-4 does not.

Under PSR-0, the class name maps directly to a file system sub-path. Given a fully-qualified class name, any PHP 5.3 namespace separators are converted to directory separators, and underscores in the class portion of the name are also converted to directory separators. (Underscores in the namespace portion proper are not converted to directory separators.) The result is prefixed with a base directory location, and suffixed with .php, to create a file path where the class file may be found. For example, the fully-qualified class name \Foo\Bar\Baz_Dib would be found in a sub-path named Foo/Bar/Baz/Dib.php on a UNIX-style file system.