Ok, I mentioned this in twitter a few weeks ago, I created an issue about it in D7’s issue queue, and there are 2 small print notes in the D6 theme guide, but I don’t think my message was visible enough. So let me just say for the record (again)…
Never, never, ever, ever use
phptemplate_ as the prefix for your theme’s preprocess functions. Don’t do it! phptemplate_ prefix should talk to the hand! Expunge it from your memory. It’s an ex-prefix. Seriously, cut it out! So, let me re-phrase:
Every time you use phptemplate_ prefix,
God adds a pointless issue to Drupal’s issue queue.
Please, think of the issue queue!
A few examples makes things clearer. Imagine you have this basetheme->subtheme hierarchy:
- subtheme1 (basetheme is its parent)
- subtheme2 (subtheme1 is its parent)
- If subtheme2 is the active theme and basetheme has a phptemplate_preprocess function, the theme registry loads all 3 theme’s template.php files and has no way to know which theme owns the phptemplate_ prefixed preprocess function. Thus, that phptemplate_preprocess function gets registered by ALL 3 of those themes and gets run three times instead of once. ouch!
- Worse case: if basetheme defines
phptemplate_preprocess()and then a un-observant subtheme1 creates the exact same function in its template.php, the unlucky themer will get a Fatal PHP error and possible WSOD (White screen of Death)! yay.
- Here's another awful consequence: Let's say that both the basetheme and the subtheme1 want to override theme_links. If basetheme defines a
basetheme_links()and subtheme1 defines a
phptemplate_links(), the one defined by subtheme1 should be used, but themeEngineName_links is assumed to be less specific than themeName_links, so subtheme1's
phptemplate_links()override is ignored in deference to the
The original rationale for allowing themeEngineName prefixes was “This makes it easier to move around code between themes and post snippets on Drupal.org.” But we already require themers to copy theme functions from modules and rename them from
themeName_function(), so the copy-and-rename-function meme is already out there. Plus, copy-and-rename will help themers who are new to programming concepts understand that you can't give 2 functions the same name.
“Portability of function names” is a crutch that we shouldn't be giving to beginning themers. It just turns them into cripples. We should teach them a little PHP the right way so we don’t confuse them more later.
So phptemplate_ prefix MUST DIE!
If you use them in your D6 themes, stop now! Better yet, go and fix them in your existing themes. Especially, if you have a contrib theme using them. For D7, I just rolled a patch for this in http://drupal.org/node/422116. Review please!