-- Karol Grecki <[email protected]> wrote (on Tuesday, 05 May 2009, 10:12 AM -0700): > Matthew Weier O'Phinney-3 wrote: > > That said, I'm going to say it once again: you should always namespace > > your classes. PHP.net recommends this, and there are great reasons why > > PEAR and ZF do as well (and most good component libraries and > > frameworks). It prevents naming collisions, makes it easier to extend > > classes, and more. > > > > It seems a bit weird to do this for models, they are domain specific, they > are not meant to be reusable in other applications, right? It's not like I > can take my User model and give it someone else to use in their application > because it's tied to my database structure etc. > I had to make this decision some time ago and chose to drop prefixes for > models because it was a bit awkward typing them for classes with specific > names often unique to my company/industry. > IMO this argument doesn't hold, prefixing libraries and frameworks is a > necessity but it makes little sense for models.
You've never re-used a "User" model from one project to another? Or a "Comments" model? or a "Tag" model? :) Yes, many times our models are non-reusable as they are application specific. However, many developers work for shops or as consultants, and code re-use is common in such cases -- hence my allusions above. Being able to have a common base that may be extended and tweaked for custom use cases is fairly normal -- and using prefixes is a standard way to prevent naming collisions in such circumstances. Once PHP 5.3 is out, some of these issues will go away -- you'll be able to use a true namespace, and keep the class name short. Until then, namespace class prefixes are the more appropriate path. As such, that common use case is what we are attempting to support with ZF's offering. -- Matthew Weier O'Phinney Project Lead | [email protected] Zend Framework | http://framework.zend.com/
