: This article mainly introduces the PHP namespace parsing rules. if you are interested in the PHP Tutorial, refer to it. PHP namespace parsing rules
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, for example, Foo \ Bar.
Fully qualified name
The name contains the namespace separator and starts 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:
- 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 find 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 ().
Name resolution example
Static methodOr the namespace function B \ foo (); // call the namespace "A \ B" function "foo" B: foo (); // call the "foo" method of class "B" defined in namespace "A" // if the class "A \ B" is not found ", then try to automatically load the class "A \ B" D: foo (); // use the import rule, call the "foo" method of class "D" defined in namespace "B" // if class "B \ D" is not found, then try to automatically load the class "B \ D" \ B \ foo (); // call the function "foo" \ B: foo () in namespace "B (); // call the "foo" method of class "B" in the global space // if class "B" cannot be found, try to automatically loadStatic methodOr function A \ B: foo (); // call the "foo" method of class "B" defined in namespace "A \ A" // if class "A \ B" is not found, then try to automatically load the class "A \ B" \ A \ B: foo (); // call the "foo" method of class "B" defined in namespace "A \ B" // if class "A \ B" is not found, then try to automatically load the class "A \ B"?>
'). AddClass ('pre-numbering '). hide (); $ (this ). addClass ('Has-numbering '). parent (). append ($ numbering); for (I = 1; I <= lines; I ++) {$ numbering. append ($ ('
'). Text (I) ;}; $ numbering. fadeIn (1700) ;}) ;}; script
The above describes the PHP namespace parsing rules, including static methods. I hope my friends who are interested in PHP tutorials will be helpful.