Here's how drupal does it, and how you can do it. Using string concatenation with naming convention. With the functions function_exists () and call_user_func_array () you must be set.
Here are two internal drupal functions that do the trick (module.inc)
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)) { return call_user_func_array($function, $args); } } function module_hook($module, $hook) { return function_exists($module .'_'. $hook); }
Therefore you only need to call
module_invoke('ModuleName','HookName', $arg1, $arg2, $arg3);
which will finally cause
ModuleName_HookName($arg1,$arg2,$arg3);
source share