|PHP 5.3 namespaces have taken away the biggest advantage of autoloading|
|When autoloading was introduced into PHP, the PHP world rejoiced as we no|
|longer needed to require every class we wanted to use in our current file|
|at the top of our code. With the introduction of namespaces this advantage|
|has been completely reversed, where unless you are writing all your code in|
|a single namespace (unlikely) you will end up needing to "use" every class|
|you want to include.|
|To back this up, let us take the Symfony2 framework as an example as of|
|today (31st January 2012).|
|jamiel@gentoo ~/git/symfony/src $ find . -name '*.php' | wc -l|
|So there are 1164 source files in the framework at the moment.|
|jamiel@gentoo ~/git/symfony/src $ egrep -r '^use ' * | wc -l|
|There are 2331 use statements so bearing in mind symfony 1.4 has|
|practically *no* fluff at the top of each class, namespaces have|
|added an extra 2331 new age require statements.|
|The top 10 all have 9 of these annoying declarations!|
|jamiel@gentoo ~/git/symfony/src $ egrep -rc '^use ' * | sed 's/\(.*\):\([0-9]\+\)/\2:\1/' | sort -r | head -n10|
|EDIT: It would seem I am not the first to find this annoying, and this has been discussed before|
|by none other than Mr. Zaninotto|
You must not use the
By the way, the
PS: It's not there to neglect the advantage of autoloading, it's just an aliasing of your classes. So that
As @pminnieur said -
And talking bout autoloading - PSR-0 just gives you ability to forget about class loading altogether either they are in root namespace or not.
If you're using
I understand that the
usestatement is only to declare which namespaces/classes the currently defined namespace/class will use and how it will declare them in
But I don't understand your point about autoload'ing and then require'ing.
Use statements are not meant to trigger the autoloading, this is right. And they don't.
So here you say we shouldn't rely on this behavior to load our classes.
I'm wondering how should I ?
Thank you !
@stephaneerard use namespaces to structurize your code and
I'm just saying that complaints like:
is the exact nonsense as saying: