1. In the thinkphp3.2 era, namespaces were not used, but the code did not look very complicated, and it did not cause much inconvenience.
2. I had seen a project done by others before. Namespace, it seems that each class file actually uses many namespaces
3. Is namespace really necessary? Will not using it cause inconvenience?
我想大声告诉你2017-06-05 11:09:17
When many of the classes you introduce have the same name, you will know the role of namespace.
For example, there is aUser class in Domain, a
User class in Service, and a
User class in Web.
phpcn_u15822017-06-05 11:09:17
For large projects, it is necessary
Otherwise, it would be bad if different libraries are introduced and functions with the same name are confused
習慣沉默2017-06-05 11:09:17
Maybe you don’t feel the role of namespaces in the projects you are exposed to now, but people should look forward. The same is true for language updates. Everything is reasonable if it exists. As for the role of namespaces, I won’t say much about it. Whatever. Google will tell you a lot about why you should use namespaces. You just need to know that it will be better if you use it. Don't people develop in a better direction?
淡淡烟草味2017-06-05 11:09:17
When discussing problems, why do we always use tp to give examples 111
怪我咯2017-06-05 11:09:17
Maybe you don’t feel the role of namespaces in the projects you are exposed to now, but people should look forward. The same is true for language updates. Everything is reasonable if it exists. As for the role of namespaces, I won’t say much about it. Whatever. Google will tell you a lot about why you should use namespaces. You just need to know that it will be better if you use it. Don't people develop in a better direction?
黄舟2017-06-05 11:09:17
In fact, the main purpose of namespace is to solve the problem of conflicts between classes with the same name.
Before there was no namespace, the old-fashioned way was to name classes according to classmap
. For example, the writing method of System_Controller.php
underline; changes to the current writing method of SystemController
;
Whether it is classmap
or namespace, just follow certain rules and then introduce it through spl_autoload_register
. It will not cause class name conflict; namespace is not necessary in the project, it is just a product of technological development!
Besides, this is very similar to other languages (such as java, etc.). Everyone is like this. If PHP is not like this, it will not keep up with the trend. . Ha ha! !