If I understand correctly, the method used to determine which theme functions are within the current theme's template.php file is drupal_find_theme_functions() in include/theme.inc, which uses PHP's function get_defined_functions().

get_defined_functions() cannot be relied on to return function names with case sensitivity. According to this PHP bug report, with regards to the poster's problem ("PHP should not be setting the function name to lower case."), andrei@cvs.php.net wrote: "That is how function names are kept internally - nothing to do about it." In addition, there are a couple comments on the PHP.net manual reporting problems with function names being converted to lowercase. (One claims this case conversion only occurs on Win32 and Unix platforms.)

In theme() of include/theme.inc, the line that compares hooks to candidate hook names is: if (isset($hooks[$candidate])) { where,

  • $candidate is case-sensitive, and
  • $hooks keys are potentially case-insensitive and lowercase.

Thus, since candidate hook names can include uppercase characters (for example including a view or block name), and some available hooks may be converted to lowercase, they can be ignored when this matching occurs.

Case in Point

These functions were placed in template.php, listed in order of most specific to least specific. Thus, the most specific function should override all the other possibilities, which is the first. (Note: These hook names were generated from views_handler_field::theme_functions() in views/handlers/views_handler_field.inc.)

function phptemplate_views_view_field__Tour__block_1__field_show_date_value($view, $field, $row) { die('1'); }
function phptemplate_views_view_field__Tour__block_1($view, $field, $row) { die('2'); }
function phptemplate_views_view_field__block_1__field_show_date_value($view, $field, $row) { die('3'); }
function phptemplate_views_view_field__block_1($view, $field, $row) { die('4'); }
function phptemplate_views_view_field__Tour__block__field_show_date_value($view, $field, $row) { die('5'); }
function phptemplate_views_view_field__Tour__block($view, $field, $row) { die('6'); }
function phptemplate_views_view_field__block__field_show_date_value($view, $field, $row) { die('7'); }
function phptemplate_views_view_field__block($view, $field, $row) { die('8'); }
function phptemplate_views_view_field__Tour__field_show_date_value($view, $field, $row) { die('9'); }
function phptemplate_views_view_field__Tour($view, $field, $row) { die('10'); }
function phptemplate_views_view_field__field_show_date_value($view, $field, $row) { die('11'); }
function phptemplate_views_view_field($view, $field, $row) { die('12'); }

There is a view block called "Tour" on the page that is loaded. '3' is printed to the loaded page, ignoring the first two defined functions. After applying the included patch, '1' is printed as is expected.

Patch

The latest trunk of Drupal 7 also appears to be affected by this bug unless there have been changes in other locations of the codebase. The patch included is for Drupal 6.12.

Effects: Will run slightly slower due to converting candidate hook names to lowercase. To alleviate this the lowercase conversion could instead take place in the Views module itself.

Assumptions: All defined hooks that are not found through PHP's get_defined_functions() are lowercase. It is possible to get rid of this assumption if needed.

Workarounds: Currently the only workaround is to use lowercase names for Views titles. Or one could simply not override hook functions including the View title.

CommentFileSizeAuthor
#1 theme.inc_d7.patch518 bytesjkitching
theme.inc_.patch366 bytesjkitching

Comments

jkitching’s picture

Version: 6.12 » 7.x-dev
StatusFileSize
new518 bytes

Added a patch for Drupal 7 trunk.

dvessel’s picture

Status: Active » Closed (won't fix)

We never supported upper case in function names. If Views still outputs uppercase in function names then please post it in the views issue queue.