Autoloading Standard,即自动加载标准。
这是PSR的第一个标准。
注意,该标准已经被标记为Deprecated,即已经废弃。更推荐使用PSR-4。
本文大部分翻译自https://www.php-fig.org/psr/psr-0/
PSR-0标准要求
- 1.命名空间和类必须遵循以下命名方法 \<Vendor Name>\(<Namespace>\)*<Class Name>
A fully-qualified namespace and class must have the following structure \<Vendor Name>\(<Namespace>\)*<Class Name> - 2.每个命名空间必须有一个最高等级的(“Vendor Name”)
Each namespace must have a top-level namespace (“Vendor Name”). - 3.每个命名空间可以拥有多个子空间
Each namespace can have as many sub-namespaces as it wishes. - 4.加载文件时每个命名空间分隔符都要转化成目录分隔符
Each namespace separator is converted to a DIRECTORY_SEPARATOR when loading from the file system. - 5.类名中下划线要转化为目录分隔符,下划线是不代表任何意思的
Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace. - 6.命名空间和类名都是以.php为后缀的文件
The fully-qualified namespace and class are suffixed with .php when loading from the file system. - 7.命名可以使用大小写
Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.
例子
- \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
关于命名空间和类名中带有下划线的情况
- \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
评价
这是一个已经废弃的标准,没什么可说的。