> php教程 > php手册 > 본문

PHPautoload PSR-0标准

WBOY
풀어 주다: 2016-06-21 08:49:27
원래의
1035명이 탐색했습니다.

1

2

3

4

5

6

7

8

9

10

11

12

13

14

function autoload($className)

{

    $className = ltrim($className, '\');

    $fileName  = '';

    $namespace = '';

    if ($lastNsPos = strripos($className, '\')) {

        $namespace = substr($className, 0, $lastNsPos);

        $className = substr($className, $lastNsPos + 1);

        $fileName  = str_replace('\', DIRECTORY_SEPARATOR, $namespace) . DIRECTORY_SEPARATOR;

    }

    $fileName .= str_replace('_', DIRECTORY_SEPARATOR, $className) . '.php';

    require $fileName;

}

 

强制约定

 

一个合格的名空间-类应当遵循这样的结构 ()*

A fully-qualified namespace and class must have the following structure ()*

每个名空间需要有一个顶级名空间 (“Vendor 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 when loading from the file system.

类名中的每个下划线符( _ )将被转化为一个路径分隔符,名空间中的下划线符( _ )没有任何特定含义

Each _ character in the CLASS NAME is converted to a DIRECTORY_SEPARATOR. The _ character has no special meaning in the namespace.

一个合格的名空间-类所对应加载的文件必须是以.php结尾的

The fully-qualified namespace and class is suffixed with .php when loading from the file system.

Vendor Name(提供者名称)、名空间、类名中的字符可以是大小写的任意组合

Alphabetic characters in vendor names, namespaces, and class names may be of any combination of lower case and upper case.



관련 라벨:
원천:php.cn
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
인기 추천
인기 튜토리얼
더>
최신 다운로드
더>
웹 효과
웹사이트 소스 코드
웹사이트 자료
프론트엔드 템플릿
회사 소개 부인 성명 Sitemap
PHP 중국어 웹사이트:공공복지 온라인 PHP 교육,PHP 학습자의 빠른 성장을 도와주세요!