Why not specify the file path after the namespace is introduced? Why not specify the file path after the namespace is introduced?
Reply content:
Why not specify the file path after the namespace is introduced?
Because there is a function used to automatically load files according to your namespace.
So it looks likeYou do not need to specify the file path
In fact, there is an automatic loading mechanism to help you require.
Add:
LZ can go to the official documentation to see: http://php.net/manual/zh/function.autoload.php
Php's Automatic Loading Function registration is a simple example
Your proposition is wrong, so there is no need to explain why.
A namespace can be simply interpreted as a long class name. For example, a Project may have two objects: \ Core \ Object and \ Project \ Object (which belong to the Core and Project namespaces respectively .) During the call, use Core \ Object or use Project \ Object indicates whether the $ obj = new Object () in the subsequent code is a Core \ Object instance or a Project \ Object instance. This has nothing to do with the specified file path.
You do not need to specify the file path from PHP's automatic loading mechanism (including the default mechanism and custom extensions in the project), instead of using the namespace. A simple counterexample: ZendFramework1 does not use namespaces, but it also implements automatic loading.
You can create a new project with only two files.
Index. php
$ Object = new \ Object ();
Create a Project directory and file Object. php
Namespace \ Project
Class Object {}
Run index. php to check the results.
You can go to Baidu for researchspl_autoload_register
Unless the automatic loading mechanism is in operation, an error is reported. Let's take a look at the automatic loading mechanism.
Http://www.cnblogs.com/quinnxu/p/4824805...