jeroen84
(Jeroendenhaan)
1
Hello all,
I have a question about namespaces… The PHP manual says the following:
Yii2 currently uses "sub-namespaces", meaning something like:
namespace yii\helpers\base;
In my opinion, this doesn’t alleviate the Extra_Long_Names problem. It might even make things more complex. (“Which namespace do I need to include??”)
What about we have 3 namespaces?
[list=1]
[*]yii
[*]app
[*]ext (this one would need sub-namespaces to avoid name collisions)
[/list]
Then we could just do:
<?php
namespace app;
use yii;
Nice and simple!
Thoughts?
You are not a developer =).
Jaggi
(Jaggi 2005)
3
You can alias long namespaces by doing the following:
use yii\helpers\base as Base;
jacmoe
(Jacob Moen)
4
When I develop in C++, I always take care to use the full namespace in the interface, especially when I program libraries to be used by others.
Haven’t used it yet in PHP, but I think it’s a good idea.
In the private implementation, I usually use ‘using namespace long_namespace’ for convenience.
jeroen84
(Jeroendenhaan)
5
Definitely true.
I am also not very experienced in using namespaces. I am just curious what the thought process behind sub-namespaces is.
Onman
(O Rijkers)
6
The idea behind sub-namespaces is to group related classes (and thus separating them from unrelated functionalities).