Autoloading classes in Drupal 6

Submitted by Larry on 3 October 2008 - 12:50am

I need to not have spare time. When I have spare time, I do crazy things. Not crazy things like your mother told you not to do, but things like write modules on a lark.

Like I said, dangerous. But, useful. In this case, it was a conversation over on Ryan Szrama's blog that kinda got out of hand and gave me another idea for a module, which I am happy to announce is now available for download.

The module is autoload. It's a simple, less than 100 line little module but gives Drupal 6 users a taste of what Drupal 7 will be like. With a single, simple hook it offers a centralized way to autoload classes and interfaces at runtime as needed, saving on code weight.

Of course, it only works under PHP 5 (which you're using anyway, right?) and only works for classes and interfaces, but if you are using classes then this module is a very quick and easy way to split up your code cleanly and efficiently to reduce page load time without needing to modify your class-using code at all.

Thank you to Ryan and Matt Farina for nudging me to actually write this. It provided a good distraction from tonight's US Vice Presidential debates and the collapse of the Cubs in game 2 of the National League Division Championship series. (Drupal, politics, and baseball, a combination that should never be repeated.)

Matt Farina (not verified)

3 October 2008 - 6:17am

Thanks for creating the module. Looks good.