A subtle bug that has been identified by the Devel (#752366: Fatal error: Call to undefined function decode_entities() in devel.module) and RSVP (#903246: Fatal error: Call to undefined function rules_include()) modules. The problem arrises when you have a menu item which loads an external file, e.g. mymodule.inc, and that module uses a custom function from the main mymodule.module file to do another action, the full bootstrap has not executed so it is unable to find the custom function. While the use cases are flawed (see my notes on the RSVP issue), Lars Toomre dug into the problem and provided a good roundup of the specifics causing the bug.

ICBW, but this may be related to other odd symptoms, like the admin theme not loading, the theme settings not updating, etc (or that could be something completely different).

Comments

Lars Toomre’s picture

Thanks for starting this bug report Damien. I meant to start one myself earlier this week. Let me elaborate on your description of this subtle bug.

Off and on for about six weeks or so, I have been trying to track down seemingly elusive odd behavior that always seems to come back to the menu_router functionality. During the course of debugging, I have learned that somewhere in the menu rebuilding process the external file (e.g. mymodule.inc) is read without being in full bootstap mode. If mymodule.inc in turn includes or requires other files, frequently the path to those include files are built either relative to the implied Druapl root (eg ./) or built with the function like drupal_get_path().

In full bootstrap mode for regular Drupal use, such path constructions generally are fine. However, during the menu building process, I have seen instances where drupal_get_path() is undefined because ./includes/common.inc either has not been included yet (?) or the attempt at inclusion failed because implicit ./ did not equal the drupal root directory. I was very surprised to see that it was possible for drupal_get_path() NOT to be defined while rebuilding the menu_router table!!

My suspicion now is that most, if not all, of the random menu_router problems will disappear on rebuilds provided:

1) The DRUPAL_ROOT constant is back-ported from D7 either as a constant or as a function call that developers can reliably use to set the base of the current drupal installation. (This helps drush and other programs that do not necessarily operate from the drupal root directory).

2) The menu_router rebuild process explicitly include DRUPAL_ROOT/includes/common.inc so that druapl_get_path() is ensured to be defined when constructing the menu items. (I solved the menu routing problems for my own modules by ensuring that the path construction logic does not include any Drupal functions. Earlier I used constructs akin to 'include_once . drupal_get_path() . /include/file.xyz'.)

I posted a possible solution for a function to set the drupal root directory from lower in the directory tree over in #752366: Fatal error: Call to undefined function decode_entities() in devel.module. Let me know how else I might help eradicate these frustrating menu router bugs.

Cheers!!

Status: Active » Closed (outdated)

Automatically closed because Drupal 6 is no longer supported. If the issue verifiably applies to later versions, please reopen with details and update the version.