Specification for automatic PHPPSR-0 loading

Source: Internet
Author: User
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 instance

The 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.