I’ve been working with PHP 5.3 for more than a year now, and there’s something I always do that I’m not sure is correct : whenever I use a class outside of the current context’s namespace, is use the use keyword :
use Another\Class
so in the code I can write directly :
$object = new Class();
That’s fine, but I often end up with a lot of use directives at the beginning of my files, and that’s not so nice to maintain (if I don’t use this class, I’m not likely to remove the use directive).
I could also write the whole namespace each time I use this class :
$object = new \Another\Class();
So I was wondering two things :
- Is there any drawback of not using the
usekeyword (except the fact that you have to write the whole namespace each time), like things you can’t do ? - Is there any drawback of using it ? (is it even slightly less performant because it somehow imports the class) ?
Edit
Just to clarify : I know clean code is more important than small performance tweaks, I just like to know when the computer is working, I like to feel the efforts 🙂
First thing that comes in my mind is the ability to use aliases like:
source php manual