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