Terrible death in hook_init (for anon users/cached page?)
dman - May 1, 2008 - 02:01
| Project: | Taxonomy context |
| Version: | 5.x-2.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | critical |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
Description
Yow. After an update to a development site last night (replaced database), my users tried to log in and got only
Fatal error: Call to undefined function: arg() in
/home/6048/domains/thevintageaviator.gomi.co.nz/html/sites/all/modules/modified/taxonomy_context-5-2/taxo
nomy_context.module on line 266(but not my sessions that were already logged in and non-caching).
I squealed "How can arg() not be available?!!!"
Seeing path.inc ...
* These functions are not loaded for cached pages, but modules that need
* to use them in hook_init() or hook exit() can make them available, by
* executing "drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);".
So I've added
<?php
/**
* Implementation of hook_init().
*/
function taxonomy_context_init() {
//
// THIS WAS CAUSING DEATH for anon users!
// Need to do this?
drupal_bootstrap(DRUPAL_BOOTSTRAP_PATH);
if(! function_exists('arg')){return;}
if (arg(0) == 'taxonomy' && arg(1) == 'term' && is_numeric(arg(2)) && empty($_GET['from'])) {
// kludge: should probably have a setting here that allows you to prevent using taxcon breadcrumbs
drupal_set_breadcrumb(taxonomy_context_get_breadcrumb(taxonomy_context_get_context()));
}
}
?>Pretty nasty surprise. Never noticed before, probably because I only just enabled caching.

#1
I think the use of the init hook in this case in unnecessary. Perhaps a better way to solve it would be to move the code that is executed in the init hook to the menu hook where there will be less issues with caching and it should resolve the issue.
#2
Agreed.
I didn't look much deeper at the time (dead site, client presentation upcoming at the time) but setting breadcrumbs is NOT a hook_init job!
#3
I'm getting this error on a fresh install as well for cached / anon user pages. Wondering on the status of this issue?