Namespace in thinkphpframework {code ...} the problem is that namespaceHomeController; the first line of code declares the space of this file, so the IndexController class is under the namespace of HomeController. This class... // namespace problems in thinkphp framework
The problem arises. namespace Home \ Controller; the first line of code declares the space of this file,
So the IndexController class is under the namespace Home \ Controller,
This class inherits the Controller class. At this time, there is no Controller class under Home \ Controller,
Although use Think \ Controller; imports another space, why?
Class IndexController extends Controller does not report an error? This is because no Controller class exists under Home \ Controller.
Why not write it as class IndexController extends Think \ Controller?
Reply content:
// Namespace problems in thinkphp framework
The problem arises. namespace Home \ Controller; the first line of code declares the space of this file,
So the IndexController class is under the namespace Home \ Controller,
This class inherits the Controller class. At this time, there is no Controller class under Home \ Controller,
Although use Think \ Controller; imports another space, why?
Class IndexController extends Controller does not report an error? This is because no Controller class exists under Home \ Controller.
Why not write it as class IndexController extends Think \ Controller?
phpuse Think\Controller;
This line of code has already imported the namespaceThink \ Controller.ControllerCategory
If you do not use:
phpuse Think\Controller;
You need to write
phpclass IndexController extends \Think\Controller\Controller {}
Try the following two sentences:
$controller = new Controller();//$controller = new IndexController();var_dump($controller);
The controller class is automatically loaded into the framework.
Http://www.php-internals.com/book/ is recommended to see how the kernel source code is achieved