search

Home  >  Q&A  >  body text

Is it necessary to use PHP namespace?

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?

天蓬老师天蓬老师2778 days ago872

reply all(8)I'll reply

  • 我想大声告诉你

    我想大声告诉你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 a

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

    reply
    0
  • 習慣沉默

    習慣沉默2017-06-05 11:09:17

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

    reply
    0
  • phpcn_u1582

    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

    reply
    0
  • PHPz

    PHPz2017-06-05 11:09:17

    Modern php is needed

    reply
    0
  • 習慣沉默

    習慣沉默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?

    reply
    0
  • 淡淡烟草味

    淡淡烟草味2017-06-05 11:09:17

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

    reply
    0
  • 怪我咯

    怪我咯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?

    reply
    0
  • 黄舟

    黄舟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.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! !

    reply
    0
  • Cancelreply