Before describing the name resolution rules, let's take a look at some important definitions:
Name resolution rules
Before describing the name resolution rules, let's take a look at some important definitions:
Namespace name definition
Unqualified name
The name does not contain the namespace separator identifier, such as Foo.
Qualified name
The name contains the namespace separator identifier, such as Foo \ Bar
Fully qualified name
The name contains the namespace separator and the identifier starting with the namespace separator, for example, \ Foo \ Bar. Namespace \ Foo is also a fully qualified name.
Name resolution follows the following rules:
Calls to fully qualified functions, classes, and constants are parsed during compilation. For example, new \ A \ B is parsed as Class A \ B.
All unqualified names and qualified names (not fully qualified names) are converted during compilation according to the current import rules. For example, if the namespace A \ B \ C is imported as C () is converted to A \ B \ C \ D \ e ().
Within the namespace, all qualified names that are not converted according to the import rules will be prefixed with the current namespace name. For example, if C \ D \ e () is called in namespace A \ B, C \ D \ e () is converted to A \ B \ C \ D \ e ().
The unqualified class name is converted during compilation according to the current import rule (the short import name is replaced by the full name ). For example, if the namespace A \ B \ C is imported as C, new C () is converted to new A \ B \ C ().
In A namespace (for example, A \ B), function calls with non-qualified names are parsed at runtime. For example, the call to function foo () is parsed as follows: 1. find the function named A \ B \ foo () in the current namespace. try to find and call the function foo () in the global space ().
Calls to A non-qualified name or qualified name class (not fully qualified name) within A namespace (for example, A \ B) are resolved at runtime. The following is the parsing process of calling new C () and new D \ E:
New C () parsing:
Find the \ B \ C class in the current namespace.
Try to automatically load class A \ B \ C.
New D \ E () parsing:
Add the name of the namespace before the class name to A \ B \ D \ E, and then search for the class.
Try to automatically load class A \ B \ D \ E.
To reference global classes in a global namespace, you must use the fully qualified name new \ C ().
The above is the namespace of note PHP-the content in the later part. For more information, see PHP Chinese website (www.php1.cn )!