From 2014-10-21 onwards, the PSR-0 standard was marked as obsolete. It is recommended to use the PSR-4 standard as replacement.
The loader (autoloader) must comply with the requirements below.
Requirements:
- A complete namespace or class must have the following structure
\ \( \)*
- Each namespace must have a top-level space name (' Vendor name ')
- Each namespace can have multiple sub-namespaces
- When loaded from the file system, separators (\) in the namespace are converted to file separators
- Each of the class names
_
(underscores) is converted to a file delimiter. _
there is no special meaning in the namespaces
- When loading from the file system, the full namespace or class must be
.php
used as the suffix name
Developer names, namespaces, and classes can consist of uppercase and lowercase letters (case-sensitive)
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
Underscores in namespaces and classes
\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
These should be the minimum standards to implement an autoloader. You can use this to load the PHP 5.3 class of autoloader to practice these standards.
Code implementation
functionautoload($className){$className= LTrim ($className,'\\');//Remove backslash in front of namespace$fileName='';$namespace='';if($lastNsPos= Strrpos ($className,'\\')) {//The position of the backslash before the class name$namespace= substr ($className,0,$lastNsPos);//Namespace$className= substr ($className,$lastNsPos+1);//class name$fileName= Str_replace ('\\', Directory_separator,$namespace). Directory_separator;//File name}$fileName. = Str_replace ('_', Directory_separator,$className).'. php ';//Standard to be suffixed with. PHP, the underscore of the class name needs to be converted to a file delimiterrequire$fileName;} Spl_autoload_register (' AutoLoad ');
Splclassloader implementation
Here is a simple splclassloader implementation that you can use to load classes if you follow the above criteria. We recommend using the PSR-0 standard to load PHP 5.3 classes
- http://gist.github.com/221634 (to turn over the wall??? )
Original Reading PSR-0
'). addclass (' pre-numbering '). Hide (); $ (this). addclass (' has-numbering '). Parent (). append ($numbering); for (i = 1; i <= lines; i++) {$numbering. Append ($ ('
'). Text (i)); }; $numbering. FadeIn (1700); }); });
The above describes the PSR-0 automatic loading standards, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.