Posted by KarenS on February 21, 2009 at 9:04pm
| Project: | Drupal core |
| Version: | 7.x-dev |
| Component: | base system |
| Category: | bug report |
| Priority: | normal |
| Assigned: | yhahn |
| Status: | needs work |
Issue Summary
In PHP 5.2 there is a new function called date_diff() which will create problems when using hook_diff() when the Date module is enabled. Not sure what to do about it, just a heads-up.
Comments
#1
Edit, I mean PHP 5.3.
#2
o man. hook #fail
will think about best path to victory for this one...
#3
That certainly explains why I cannot find the date_diff() in the date module that I happen to have installed.
The only thing I can imagine doing is adding a more unique string to the _diff() hook, but that would break existing modules.
Is it possible to blacklist certain names for drupal hooks?
I will look into this as well as I would like to get this solved asap.
#4
After looking around the PHP docs, this seems to be what we want to use:
http://us3.php.net/manual/en/function.get-defined-functions.php
PHP core functions get stored in the array called:
internalAll others seem to get stored in the array called:
userThe drupal_hook() needs to be changed to only call a hook if it is defined in the
userarray.I have attached a patch that makes this check for drupal 6.x.
The patch changes
module_invokeandmodule_invoke_allto have the following added:<?php
$defined = get_defined_functions();
if (is_array($defined) && array_key_exists('user', $defined) && in_array($function, $defined['user'])){
// function calls wrapped here
}
?>
I have moved this thread to drupal core because I believe this is the proper solution to this problem.
If you think otherwise, please move this issue back to the Diff project.
#5
Bumping to D7 for consideration. Changing module_hook() seems to be the only thing necessary here.
#6
I wonder what would happen if the
get_defined_function()failed to return a properly populated array.I am now thinking that if the
get_defined_function()function failed to return sane results that the code should gracefully fail.Would
isset()be a better choice in this case thanis_array($defined) && array_key_exists('user', $defined)?For example:
<?php
$defined = get_defined_functions();
if ((isset($defined['user']) && in_array($function, $defined['user'])) || !isset($defined['user'])){
// function calls wrapped here
}
?>
The idea with that change would be to fallback to previous behavior if the
$definedvariable is not properly populated.EDIT:
After reading #5, I just tried only changing
module_hook(), but the original php error message appears.Did you mean
module_hook_all()?I also just tried only changing
module_hook_all()instead ofmodule_hook()and the original php error message does not appear.#7
#8
#4: drupal-6.x-avoid_internal_hookage-1.patch queued for re-testing.
#9
The last submitted patch, drupal-6.x-avoid_internal_hookage-1.patch, failed testing.