thinkphp 有自动加载 为什么还要use呢

今天有人在群里面讨论这个问题。

tp5官方文档介绍自动加载:命名空间的路径与类库文件的目录一致,那么就可以实现类的自动加载
比如说app\index\controller这个空间下有两个类库 index跟test
我如果想要在test里面调用index下面的tests方法的话。
贴代码
public function index() { $test=new Index(); $test->tests(); }
并且在test里面不需要写use tp5已经自动加载了
但是如果要调用app\test\controller(不同命名空间) 下的index类库 两种写法
一:

use app\test\controller\Index;

 public function index()
    {
    	$test=new Index();
    	$test->tests();
    }

二:

public function test2(){
    	$test=new \app\test\controller\Index;
    	$test->tests();
    }

猜你喜欢

转载自blog.csdn.net/qq_36899235/article/details/84027053