For example, if there are two class files {code...}, how can I write them in c. php? Whether to write {code...} or directly {code...}, for example, two class files
a.phpnamespace A;class Test1{}b.phpnamespace B;class Test2{}
So how to write it in c. php? Yes write
include('a.php');$c = new \A\Test1()
Or directly
use A;$c = new \A\Test1()
Reply content:
For example, two class files
a.phpnamespace A;class Test1{}b.phpnamespace B;class Test2{}
So how to write it in c. php? Yes write
include('a.php');$c = new \A\Test1()
Or directly
use A;$c = new \A\Test1()
No. Continuing to include only reduces the possibility of xxxx name conflicts in new xxxxx files.
The namespace only solves the problem of duplicate names and also needs to introduce files. Of course, you can also use composer for package management.
The landlord, look at the psr-4 and psr-0.
File loading and namespace are two different things. It can be automatically loaded without using a namespace.
For more information about automatic loading, see:
Spl-autoload-register
The two are not a concept at all. Include is the introduction file, namespace is encapsulation, Class Classification
C. php:
include('a.php');use A\Test1;$c = new Test1();