Is it necessary to use PHP namespace?
天蓬老师
天蓬老师 2017-06-05 11:07:17
0
8
851

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?

天蓬老师
天蓬老师

欢迎选择我的课程,让我们一起见证您的进步~~

reply all(8)
我想大声告诉你

When many of the classes you introduce have the same name, you will know the role of namespace.

For example, there is a

User class in Domain, a User class in Service, and a User class in Web.

習慣沉默

When discussing problems, why do we always use tp as an example

phpcn_u1582

For large projects, it is necessary

Otherwise, it would be bad if different libraries are introduced and functions with the same name are confused

PHPzhong

Modern php is needed

習慣沉默

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?

淡淡烟草味

When discussing problems, why do we always use tp to give examples 111

刘奇

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?

黄舟

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.phpunderline; 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! !

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template