Wondering how Drupal manages hooks outside of the core in modules. Seems like parsing the code in modules would add a lot of overhead, and that it's more likely that the code is doing something else to manage the calls; for example, indexing or compiling the code when Drupal boots for the first time.

If there's a difference between how 6 and 7 handles this, please explain how each handles it, or clearly state which version you've explained.

1 Answer 1


I can't speak for Drupal 6 (haven't used it in a while), but in Drupal 7 the standard method used to invoke a hook is something like the following:

$modules = module_implements('some_hook');
foreach ($modules as $module) {
  // Call the hook

module_implements() caches the hook implementations, and as such the index is only rebuilt when the caches are cleared (or more specifically, the bootstrap cache).

As for parsing the code in modules, this falls outside of Drupal's jurisdiction; PHP will parse all of the code in any included file. Since hooks must reside in a .module file (or at least a file that's explicitly included from a module file), and all enabled module files are included on each page request, the whole file will be parsed every time.

  • 3
    The actual detection of hooks is a simple function exists for each hook/module combination. 6.x works the same, except that there is no caching.
    – Berdir
    Jun 8, 2012 at 13:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.