In the following code, if css_emimage_preprocess_page is the first item in the 'preprocess functions' registry array, it will return 0 as the index and therefore set $key = 0. Anything that evaluates to zero as a condition in PHP is the same as FALSE.
In your code, if css_emimage_preprocess_page is the first item, it will fail the if condition and set it again without removing it from the array (now you have the item set twice in the array). This may have unintended consequences. Since the purpose of that code is to move css_emimage_preprocess_page to bottom of the array, I assume making sure it runs last is important.
/**
* Implementation of hook_theme_registry_alter().
*
* Make css_emimage's page preprocess function run after everything else.
* If the css_gzip module is installed, move it's preprocess function after ours.
*/
function css_emimage_theme_registry_alter(&$theme_registry) {
if (isset($theme_registry['page'])) {
// Move our preprocess function after everything else.
if ($key = array_search('css_emimage_preprocess_page', $theme_registry['page']['preprocess functions'])) {
unset($theme_registry['page']['preprocess functions'][$key]);
}
$theme_registry['page']['preprocess functions'][] = 'css_emimage_preprocess_page';
// Move css_gzip's preprocess function after ours.
if ($key = array_search('css_gzip_preprocess_page', $theme_registry['page']['preprocess functions'])) {
unset($theme_registry['page']['preprocess functions'][$key]);
$theme_registry['page']['preprocess functions'][] = 'css_gzip_preprocess_page';
}
}
}
Comments
Comment #1
philbar commentedConsider using a boolean-based function like in_array() instead of array_search(), which returns mixed results.
Comment #2
jcarnett commentedUnder normal circumstances this won't cause an issue (the zero index is typically used by the template engine), but it's a bug nonetheless. A fix has been commited to CVS:
Thanks for bringing it to my attention.