[size=10]originating from [[http://www.php-fig.org/psr/psr-0/|PHP-FIG PSR-0]][/size] ====== Autoloading Standard ====== As of 2014-10-21 PSR-0 has been marked as deprecated. PSR-4 is now recommended as an alternative. The following describes the mandatory requirements that must be adhered to for autoloader interoperability. ===== Mandatory ===== * A fully qualified namespace and class name must have the following structure: ''\\(\)*'' * Each namespace must have a top-level namespace ("Vendor Name"). * Each namespace can have as many sub-namespaces as it wishes. * Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system. * Each **_** character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. :!: //Adaptation for WB:// The **_** has no special meaning in the __normal__ definition of a namespace, with pseudo-namespaces (see [[en:dev:all:psr:psr-1|PSR-1]]) it will be converted to a DIRECTORY_SEPERATOR which forbids in this case, folder and file names containing **_**. * The fully-qualified namespace and class is suffixed with **.php** when loading from the file system. * Alphabetic characters (AZ) in vendor names, namespaces and classes can be any combination of uppercase and lowercase letters. :!: In [[en:dev:all:psr:psr-1|PSR-1]] this will be further restricted! ===== Examples ===== \Doctrine\Common\IsolatedClassLoader => /path/to/project/lib/vendor/Doctrine/Common/IsolatedClassLoader.php \Symfony\Core\Request => /path/to/project/lib/vendor/Symfony/Core/Request.php \Zend\Acl => /path/to/project/lib/vendor/Zend/Acl.php \Zend\Mail\Message => /path/to/project/lib/vendor/Zend/Mail/Message.php ===== Underscores in Namespaces and Class Names ===== \namespace\package\Class_Name => /path/to/project/lib/vendor/namespace/package/Class/Name.php \namespace\package_name\Class_Name => /path/to/project/lib/vendor/namespace/package_name/Class/Name.php The standards we set here should be the lowest common denominator for painless autoloader interoperability. You can test that you are following these standards by utilizing this sample SplClassLoader implementation which is able to load PHP 5.3 classes. ===== Example Implementation ===== Below is an example function to simply demonstrate how the above proposed standards are autoloaded. ===== SplClassLoader Implementation ===== The following gist is a sample SplClassLoader implementation that can load your classes if you follow the autoloader interoperability standards proposed above. It is the current recommended way to load PHP 5.3 classes that follow these standards. [[http://gist.github.com/221634|gist.github.com/221634]]