1. Use alias for namespace name
That is to introduce other namespaces into the namespace and use the use operator to implement them.
After the introduction of other namespaces, you can simply prefix the element with a subnamespace, instead of writing all the introduced space names
Namespace app1\pro1\item1 is introduced in namespace app2\pro2\item2\topic2, and the subspace name item1 is added before the element when it is used
2. Use alias for class name
Classes are widely used in php, which provides a way to introduce classes in a namespace.
The class Fruit is defined in the namespace app1\pro1\item1. After the class of the previous namespace is introduced in the namespace app2\pro2\item2\topic2, the class element can be called directly
3. Introduce other namespaces into the public namespace
In php, the space where the elements without a namespace are located is the public namespace, and the way that the public namespace is introduced into other namespaces is include(), and the path is filled in brackets.
Calls without a clear prefix will look for the element in the current space. If they cannot find it in the namespace, an error will be reported;
A single \ prefix accesses the func() function in the public namespace;
Use elements of the introduced namespace, use fully qualified names
Define a test1.php file as follows:
Create a new test.php file in the same level directory, and introduce test1.php: