\module_invoke
function
Invoke a hook in a particular module.

Invoke a hook in a particular module.

Comments

emanaton’s picture

It is useful to realize that the args passed to invoked functions are not passed by reference with calls to module_invoke() (or to module_invoke_all(), for that matter).

Dave Goldman’s picture

PHP 5.3 (5.2?), changed the way that call_user_func_array() treats args passed by reference.

Here's how I've modified module_invoke() to deal with this:

function module_invoke() {
  $args = func_get_args();
  $module = $args[0];
  $hook = $args[1];
  unset($args[0], $args[1]);
  $function = $module . '_' . $hook;
  if (module_hook($module, $hook)) {
    if (strnatcmp(phpversion(),'5.2')  &$arg) {
        $ref_args[$key] = &$arg;
      }
      return call_user_func_array($function, $ref_args);
    }
  }
}

The function module_invoke_all() needs a similar change.

[Follow-up:] This is not actually a good fix. See http://drupal.org/node/353494

barteque’s picture