Allowing alias reference or external fully qualified names is an important feature of a namespace. This is similar to creating symbolic connections to other files or directories in unix-like file systems. The PHP namespace supports two alias or import methods: use an alias for the class name or use an alias for the namespace name. Note that PHP does not support importing functions or constants. Allowing alias reference or external fully qualified names is an important feature of a namespace. This is similar to creating symbolic connections to other files or directories in unix-like file systems.
The PHP namespace supports two alias or import methods: use an alias for the class name or use an alias for the namespace name. Note that PHP does not support importing functions or constants.
In PHP, aliases are implemented through the use operator. The following is an example of using all three possible import methods:
Example #1 use the use operator to import/use aliases
Note: For the name in the namespace (the fully qualified name that contains the namespace separator, such as Foo \ Bar, and the global name that does not contain the namespace separator, such as FooBar, the leading backslash is unnecessary or not allowed, because the imported name must be fully qualified and will not be parsed relative to the current namespace.
To simplify the operation, PHP also supports multiple use statements in one line.
Example #2 import/use aliases using the use operator. a row contains multiple use statements.
The import operation is compiled and executed, but the dynamic class name, function name, or constant name is not.
Example #3 Import and dynamic name
In addition, the import operation only affects non-qualified names and qualified names. The fully qualified name is determined, so it is not affected by the import.
Example #4 import and fully qualified names