Submitted by Guest on Wed, 04/28/2010 - 10:00am

Having a static class buys you nothing over just a bunch of functions in PHP. You don't get the free extra layer of indirection of having an object. You can't pass it to another function or method as a parameter. Before 5.3 you can't even extend a static class in anything resembling a useful way.

What you're talking about providing is a utility library for yourself. That's all well and good and makes total sense to do, but just wrapping functions in a class does not a library make. And it doesn't save you from declaring the code twice in two different modules that need it and causing PHP to crash, same as any other code library.

What you want is a utility module with functions. Those are easy. Create a module with no UI components, just an info file and a .module file with your utility library in it. Then make it a dependency for your real site-specific modules. Problem solved, in a way that other Drupal developers will understand, gets you the same benefit as coping and pasting a static class (and then some, since you don't need to re-copy-and-paste each time you update it), and doesn't lead you or anyone else down the wrong path about what OO is or what it actually gets you. Just using the word "class" does not make something OO.

As for MVC, well, that's already been extensively covered elsewhere:
http://www.garfieldtech.com/blog/mvc-vs-pac
http://engineeredweb.com/blog/10/4/its-time-nomvc

Short version: Ruby on Rails is not the definition of MVC.

Documentation also has nothing to do with MVC or OO. Drupal is very well documented overall, although it certainly has room for improvement. Every function or method in Drupal *should* have a full docblock on it; Drupal nominally uses a variant of Doxygen rather than phpDocumentor, but the differences are small and we're moving in the direction of being more like phpDoc. All of core gets parsed and the API documentation made available here: http:;//api.drupal.org/

If you find code in Drupal that doesn't have a docblock on it yet, that is a bug. Please file a patch. :-)

The content of this field is kept private and will not be shown publicly.

Plain text

  • Lines and paragraphs break automatically.
  • Web page addresses and email addresses turn into links automatically.