Php alias and import

Source: Internet
Author: User
Allowing alias reference or external fully qualified names is an important feature of a namespace. This is similar to creating symbolic connections to other files or directories in unix-like file systems. The PHP namespace supports two alias or import methods: use an alias for the class name or use an alias for the namespace name. Note that PHP does not support importing functions or constants. Allowing alias reference or external fully qualified names is an important feature of a namespace. This is similar to creating symbolic connections to other files or directories in unix-like file systems.

The PHP namespace supports two alias or import methods: use an alias for the class name or use an alias for the namespace name. Note that PHP does not support importing functions or constants.

In PHP, aliases are implemented through the use operator. The following is an example of using all three possible import methods:

Example #1 use the use operator to import/use aliases

 

Note: For the name in the namespace (the fully qualified name that contains the namespace separator, such as Foo \ Bar, and the global name that does not contain the namespace separator, such as FooBar, the leading backslash is unnecessary or not allowed, because the imported name must be fully qualified and will not be parsed relative to the current namespace.

To simplify the operation, PHP also supports multiple use statements in one line.

Example #2 import/use aliases using the use operator. a row contains multiple use statements.

 

The import operation is compiled and executed, but the dynamic class name, function name, or constant name is not.

Example #3 Import and dynamic name

 

In addition, the import operation only affects non-qualified names and qualified names. The fully qualified name is determined, so it is not affected by the import.

Example #4 import and fully qualified names

 

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.