Symfony2: New generation PHP autoloading

There is an article on the state of autoloading in PHP frameworks which says that in new frameworks the use of namespaces is a step backwards to the days of require_once littering the top of files. I disagree with this for the following reasons.

IDE handling

After giving some advantages, the article then says that the overriding disadvantage is the maintenance of the use statements as the top of the file, claiming that this will require finding the class in the directory structure and copying and pasting the namespace.

I have found that Eclipse’s autocomplete will find the class for me and automatically insert the use statement if needed so this is just not an issue if you are using Eclipse. I’m sure it will be similar for Netbeans and other proper IDEs. If some editors do not not support this then it is surely an issue with that editor rather than a reason why namespacing should not be being used effectively in PHP frameworks.

It’s only shorthand

You do not need the use statements at all if you do not want them, just use the full namespaced version. Other then syntax this is no different to the previous generation of autoloading with long class names that effectively contained the path. So PathToClassClassName rather than PathToClass_ClassName

Use Dependency Injection anyway

The article single Symfony2 as a new generation framework in which this is an issue. In Symfony2 there is an excellent Dependency Injection container. If you use this there is no need to be autoloading classes in your code anyway, use DI to pass them in and then the only need for the class paths and use statements will be for type hinting the injection point, which is optional anyway.