PHPackages                             paulyg/autoloader - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [PSR &amp; Standards](/categories/psr-standards)
4. /
5. paulyg/autoloader

ActiveLibrary[PSR &amp; Standards](/categories/psr-standards)

paulyg/autoloader
=================

A simple and lightweight PSR-0 and PSR-4 class autoloader

v1.0.0(12y ago)32461MITPHP

Since Jan 1Pushed 12y ago1 watchersCompare

[ Source](https://github.com/paulyg/autoloader)[ Packagist](https://packagist.org/packages/paulyg/autoloader)[ Docs](https://github.com/paulyg/autoloader)[ RSS](/packages/paulyg-autoloader/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

\##Synopsis

`Paulyg\Autoloader` is about the smallest and simplest PHP class autoloader you can imagine. It loads classes following both the established and popular [PSR-0 standard](http://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md) and the recently ratified [PSR-4 standard](http://github.com/php-fig/fig-standards/blob/master/accepted/PSR-4-autoloader.md). It uses PHP's internal SPL stack to keep track of prefix-directory mappings rather than doing it in userland code.

\##Motivation

There are plenty of autoloading libraries and components already for PHP. So why would I want to write my own? My original motivation was to eliminate the many empty directories that are a consequence of the PSR-0 directory structure. This gets exasperated if you are using [Composer](http://getcomposer.org) to manage libraries. Here is an example, pretend we are using` Zend\Feed`, which pulls in `Zend\Stdlib` and `Zend\Escaper`.

```
/path/to/project/vendor/zendframework/zend-feed/Zend/Feed/
/path/to/project/vendor/zendframework/zend-stdlib/Zend/Stdlib/
/path/to/project/vendor/zendframework/zend-escaper/Zend/Escaper/
                              |             |       |     |
                              |             |       |     `-- Finally code here!
                              |             |       |
                              |             |       `-- No code in this dir
                              |             |
                              |             `-- No code in this dir
                              |
                              `-- No code in this dir

```

I was constantly traversing those empty directories in my own code and in looking at library code. Composer enforces the first two directories, e.g. `zendframework/zend-blah`, as part of its own *namespacing* scheme. But at least I could squash the other two. I called this **aliasing**, and the first version of this autoloader had a method called `addAlias()`. Later I saw the [PSR-4 proposal](https://groups.google.com/forum/#!topic/php-fig/qT7mEy0RIuI) from [PHP-FIG](http://www.php-fig.org "PHP Framework Interop Group") that is essentially the same idea. So that method got renamed to `addPsr4()`, even though PSR-4 has still not been ratified. *Disclaimer: I have no affiliation with PHP-FIG.*

The PSR-4 autoloading standard allows you to stucture library code like so.

```
/path/to/project/vendor/zf/zend-feed/Reader.php
