Php-namespace keyword and _ NAMESPACE _ constant

Source: Internet
Author: User
PHP supports two abstract methods to access the internal elements of the current NAMESPACE, __namespace _ magic constant and namespace keyword. The constant _ NAMESPACE _ value is a string containing the name of the current NAMESPACE. Globally, code that is not included in any namespace contains an empty string. PHP supports two abstract methods to access the internal elements of the current NAMESPACE, __namespace _ magic constant and namespace keyword.

The constant _ NAMESPACE _ value is a string containing the name of the current NAMESPACE. Globally, code that is not included in any namespace contains an empty string.

Example #1 _ NAMESPACE _ Example, the code in the NAMESPACE

 

Example #2 _ NAMESPACE _ Example, global code

 

Constant _ NAMESPACE _ is useful when a name is dynamically created, for example:

Example #3 use _ NAMESPACE _ to dynamically create a name

 

The keyword namespace can be used to explicitly access elements in the current namespace or sub-namespace. It is equivalent to the self operator in the class.

Example #4 namespace operator, code in namespace

 

Example #5 namespace operator, global code

 

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.