例如2个类文件
a.php
namespace A;
class Test1{
}
b.php
namespace B;
class Test2{
}
那么在c.php里怎么写呢?是写
include('a.php');
$c = new \A\Test1()
还是直接
use A;
$c = new \A\Test1()
天蓬老师2017-04-10 17:26:44
楼主,看下psr-4和psr-0。
文件的加载和命名空间是两回事。不使用命名空间一样可以实现自动加载。
关于自动加载可以看下:
spl-autoload-register
PHPz2017-04-10 17:26:44
两者根本不是一个概念。include是引入文件,命名空间是封装,对类分类
c.php写法:
include('a.php');
use A\Test1;
$c = new Test1();