Created some entries, logged out, and now I can't get any page to load but I get this error:

Fatal error: Call to undefined function base_path() in /var/www/aigeanta.net/sites/all/modules/path_redirect/path_redirect.module on line 32

Comments

HorsePunchKid’s picture

As a temporary workaround, you could replace base_path() with $GLOBALS['base_path']; if that works, then we'll just use that instead. If that doesn't work, you can try hardcoding your particular base path (the directory where Drupal is installed) to get your site working again.

Please let me know if the first suggestion works!

icecreamyou’s picture

Same problem, only happens for anonymous users. I might try your suggestion later, right now I've just disabled the module.

müzso’s picture

Title: undefined function base_path » explanation of the bug

The Drupal bootstrap procedure consists of the following phases (at least in Drupal 5.x):

  1. DRUPAL_BOOTSTRAP_CONFIGURATION
  2. DRUPAL_BOOTSTRAP_EARLY_PAGE_CACHE
  3. DRUPAL_BOOTSTRAP_DATABASE
  4. DRUPAL_BOOTSTRAP_ACCESS
  5. DRUPAL_BOOTSTRAP_SESSION
  6. DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE
  7. DRUPAL_BOOTSTRAP_PATH
  8. DRUPAL_BOOTSTRAP_FULL

The base_path() function is defined in includes/common.inc, but this is only loaded in the last step, DRUPAL_BOOTSTRAP_FULL. However the implementations of hook_init are executed in DRUPAL_BOOTSTRAP_LATE_PAGE_CACHE, where the base_path() function is not yet defined/loaded.

Actually this function merely returns $GLOBALS['base_path'], so using this variable instead of the function is a safe bet at the moment (however this might change in future so keep an eye out for Drupal upgrades). The value of the global $base_path variable is defined in the first step of bootstrap (DRUPAL_BOOTSTRAP_CONFIGURATION), so you can safely reference and use it in hook_init functions.

To summerize: replacing the base_path() function call with a reference to the $base_path global variable (or $GLOBALS['base_path'], which is the same) in path_redirect.module's 32nd line is a safe and correct fix for the bug. Of course one might think about the necessity of using hook_init ... maybe using hook_menu might be feasible too, which would solve the undefined base_path() problem as well.

müzso’s picture

Title: explanation of the bug » Call to undefined function base_path()

Sorry, I mistakenly updated the title of the bug request to something else (fixed now). I didn't read the note above the "Issue title" field on the comment submission form previously. :-(

HorsePunchKid’s picture

Assigned: Unassigned » HorsePunchKid

Thank you for the excellent write-up, müzso. I'll get a patch in ASAP unless someone beats me to it...

HorsePunchKid’s picture

Status: Active » Fixed

Committed; thanks again!

Anonymous’s picture

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.