PHP Namespace conventions - doubling namespaces -


from time time keep seeing doubled namespaces like:
namespace/namespace/subnamespace/

for example new prestashop (1.7) uses convention
namespace prestashop\prestashop\core;

could explain me benefits of type of namespacing?

also tutorials namespacing this:

namespace mynamespace/classname classs classname {} 

what benefits of this? cause see disadvantages as: more complicated namespaces , more typing.

also saw q&a: php namespace questions
can see disadvantage: more prone bugs depends on relative namespacing

ps: keep on using absolute namespaces. it's less prone bugs in feeling, enlighten me if i'm wrong please.

as mentioned auto-loading , follows psr-4 conventions. naming convention namespaces left creator. required piece top level namespace there can many sub-namespaces used if wanted.

for example in prestashop's composer.json have:

"autoload": {     "psr-4": {         "prestashop\\prestashop\\": "src/",         "prestashopbundle\\": "src/prestashopbundle/"     } } 

so namespace prestashop\prestashop\ can thing within src.

in slim framework (a router) have:

"autoload": {     "psr-4": {         "slim\\": "slim"     } } 

so in 1 use namespace slim\class.

in 1 of first project did like:

"autoload": {     "psr-4": {         "app\\models\\": "app_name/models",         "app\\validators\\": "app_name/validators"         //and on     } } 

i not think hurts redundant in end.


Comments