For example, 2 classes of files
a.phpnamespace A;class Test1{}b.phpnamespace B;class Test2{}
So how do you write it in c.php? is to write
include('a.php');$c = new \A\Test1()
or a direct
use A;$c = new \A\Test1()
Reply content:
For example, 2 classes of files
a.phpnamespace A;class Test1{}b.phpnamespace B;class Test2{}
So how do you write it in c.php? is to write
include('a.php');$c = new \A\Test1()
or a direct
use A;$c = new \A\Test1()
No, continue to include only reduces the likelihood of the XXXX naming conflict in the new xxxxx in different files
namespaces only solve the problem of duplicate names, and you also need to introduce files. Of course, you can also use composer for package management.
Landlord, look at the psr-4 and psr-0.
File loading and namespaces are two different things. Automatic loading is possible without the use of namespaces.
About automatic loading can be seen below:
Spl-autoload-register
They are not a concept at all. Include is the introduction of files, namespaces are encapsulated, classes are categorized
c.php notation:
include('a.php');use A\Test1;$c = new Test1();