PHP namespace parsing rules
namespace name definition
Unqualified names unqualified Name
名称中不包含命名空间分隔符的标识符,例如Foo
Qualified name qualified name
名称中含有命名空间分隔符的标识符,例如:Foo\Bar
Fully qualified name fully qualified name
名称中包含命名空间分隔符,并以命名空间分隔符开始的标识符,例如:\Foo\Bar.namespace\Foo 也是一个完全限定名称。
Name resolution follows these rules
- Calls to fully qualified names for functions, classes, and constants are parsed at compile time. For example, new \a\b resolves to class a\b.
- All unqualified and qualified names (not fully qualified names) are converted at compile time according to the current import rules. For example, if the namespace a\b\c is imported as C, then the call to C\d\e () is converted to a\b\c\d\e ().
- Inside the namespace, all qualified names that are not translated according to the import rule are preceded by the current namespace name. For example, if you call C\d\e () inside the namespace a\b, C\d\e () is converted to a\b\c\d\e ().
- Unqualified class names are converted at compile time based on the current import rule (instead of the short import name with the full name). For example, if the namespace a\b\c is imported as C, then new C () is converted to new a\b\c ().
- Within a namespace (for example, a\b), a function call to an unqualified name is parsed at run time. For example, the call to function foo () is parsed like this:
- Look for a function named A\b\foo () in the current namespace
- Try to find and invoke the function foo () in global space.
Calls to unqualified or qualified name classes (not fully qualified names) within a namespace (for example, a\b) are resolved at run time. Here is the parsing process for calling new C () and New D\e ():
Resolution of New C ():
Finds the A\b\c class in the current namespace;
Attempt to automatically load class a\b\c.
Parsing of New D\e ():
Precede the class name with the current namespace name into: A\b\d\e, and then look for the class
Attempt to automatically load class a\b\d\e.
In order to refer to global classes in the global namespace, you must use the fully qualified name new \c ().
Name resolution Example
Static methodsor namespace function B\foo (); Call namespace "a\b" in function "foo" B::foo (); Call the "Foo" Method of Class "B" defined in the namespace "A"//If the class "a\b" is not found, try to automatically load the class "a\b" D::foo (); Using the import rule, call the "Foo" Method of Class "D" defined in the namespace "B"///If the class "b\d" is not found, try to automatically load class "B\d" \b\foo (); Call the function "foo" in the Namespace "B" \b::foo (); Call the "Foo" Method of Class "B" in global space//If class "B" is not found, try to automatically load the class "B"//////in the current namespaceStatic Methodsor function A\b::foo (); Call the "Foo" Method of Class "B" defined in the namespace "a\a"///If the class "a\a\b" is not found, try to automatically load the class "a\a\b" \a\b::foo (); Call the "Foo" Method of Class "B" defined in the namespace "a\b"///If the class "a\b" is not found, 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); }); });
The above describes the PHP namespace parsing rules, including the static method aspects of the content, I hope that the PHP tutorial interested in a friend helpful.