摘自:https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md
- A fully-qualified namespace and class must have the followingstructure
\<Vendor Name>\(<Namespace>\)*<Class Name>
- 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
whenloading from the file system. - Each
_
character in the CLASS NAME is converted to aDIRECTORY_SEPARATOR
. The_
character has no special meaning in thenamespace. - The fully-qualified namespace and class is suffixed with
.php
whenloading from the file system. - Alphabetic characters in vendor names, namespaces, and class names maybe of any combination of lower case and upper case.
- A fully-qualified namespace and class must have the followingstructure
大致翻译:
- 命名空间与类的结构为:\供应商\命名空间\类名。
- 每个命名空间必须有顶级(供应商)
- 每个命名空间可以有多个子命名空间。
- 每个命名空间分割可被转化“/”(目录分割符),当从文件系统中加载的时候。
- 类名中的_下划线可被转化成“/”(目录分割符),这个符号没有特殊的意思。
- 类与命名空间后缀以“.php”结尾,当从文件系统中加载的时候。
- \供应商\命名空间\类名的字符随便是小写或大写。
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