About the benefits of namespace
They have obvious advantages:
- help shorten class names;
- Avoid name conflicts;
- help to better structure classes.
But, besides this, there is another advantage that is not often paid attention to: namespace 's help the developer to see the dependencies of a particular class, and this does not lead to any overhead. I will explain.
Remember how in PHP4 we wrote before declaring a class: Then came PHP5, __autoload () and spl_autoload_register () appeared
require_once "MyClassParent.php";
require_once "MyClassDependency.php";- we removed unconditional file connections and overhead with them. Everything is fine, but now it’s not so obvious what other classes / files are needed for our class to function normally.
And here - the php-5.3
use myns::MyClassParent;
use anotherns::MyClassDependency;