I’ve just begun learning Symfony2 (after using 1.x for the past 2 years) and am kind of put off by how much more typing is required. I know that sounds lazy, but I love the fact that I can quickly get something up and running in 1.x with much less typing. I’m wondering if it’s possible to autoload classes without needing to use namespaces. All my attempts to do so (using the PEAR naming scheme) have failed.
If I’m missing something obvious and would be shooting myself in the foot by avoiding using namespaces, I’d appreciate any advice 🙂
In response to @KingCrunch:
I’d like to avoid the namespace and use declarations that seem to be used very frequently in Symfony2 simply to speed up my coding. To be honest, I haven’t used namespaces in PHP before. I understand their benefit on paper (and I’m used to using packages in other languages) but I’ve never run into an issue by not using them in Symfony 1.x projects. This is why I made the “If I’m missing something…” statement above.
You have to realize that namespaces are not requiring you any more typing than PEAR-style names. Actually they can save up some characters.
See those two examples:
With PEAR-style:
With namespaces/use:
With namespaces, but no use:
As you see, if you use fully qualified class names every time (last example), you just have one more char per class name, the leading
\. If you use the use statements and all, then it gets shorter the more you re-use the same class names in one file, or the more classes you use that are in the same namespace.TL;DR: Anyway, if you’re lazy, get an IDE like PhpStorm that will autocomplete all those and add the use statements for you.