PHPPSR-0 automatic loading Specification automatic loading specification
This specification has been deprecated-This specification was marked as obsolete in October 21, 2014 and the latest alternative specification is [PSR-4].
This document describes the encoding rules to be followed for the autoloader.
Specifications
The definition of a standard namespace and class name must comply with the following structure:
\ \( \)* ;
The Vendor Name is the Name of a top-level namespace that each namespace must have;
If needed, each namespace can have multiple sub-namespaces;
When a class file is loaded from the file system based on the complete namespace name, the delimiter between each namespace is converted into a folder path separator;
Each _ character in the class name is also converted into a folder path separator, while the _ character in the namespace has no special meaning.
When a standard namespace or class is loaded from the file system,. php is added as the target file suffix;
The organization Name, Namespace, and Class Name can be composed of any uppercase and lowercase letters.
Example
\ 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
The namespace and the underline in the class name
\ 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 above is the minimum standard that must be followed for general automatic loading. you can use the following example function SplClassLoader to load class files in PHP 5.3, to verify that the namespace and the class you write comply with the preceding rules.
Instance
The following example function is a simple implementation of this specification.
SplClassLoader instanceThe following gist is an instance of the SplClassLoader class file. if you follow the above rules, you can use it to load your class file. This is also the recommended method for loading class files in PHP 5.3.
Gist address