Community Documentation

Drupal's code registry

Last updated February 8, 2013. Created by beejeebus on December 24, 2008.
Edited by nedjo, Shnapoo, mlncn, clemens.tolboom. Log in to edit this page.

Drupal 7 introduces a code registry - an inventory of all classes and interfaces for all enabled modules and Drupal's core files. The registry stores the path to the file a given class or interface is defined in, and loads the file when necessary.

The registry loads classes and interfaces on demand, via php's built in class autoloading mechanism.

Modules can now move all code for classes that are not regularly used into an include file, and Drupal will only load it on demand. This will cut down on the amount of code loaded per request, and reduce Drupal's memory footprint.

The only file unconditionally loaded by Drupal for a given module is module_name.module. Any code that must always be available without using the registry should be put in this file.

The registry is rebuilt when modules are enabled or disabled in order to incorporate new code or remove code from disabled modules. If you are developing new code with classes, make sure to rebuild the registry regularly so that new resources are incorporated. (Clearing all caches or calling registry_rebuild() directly both will do this.) Rebuilding an existing registry to incorporate new changes is not that expensive, as the registry will not reparse files that have the same path and modification time as the last build.

Under certain conditions a stale file registry can lead to errors that block access to a site. The Registry rebuild project provides tools to help address this problem.

Note Files that do not contain classes and interfaces that might be put into use at any time by your module file do not need to be listed with the files[] property in your .info file. Instead, such code can continue to be loaded when you need it, such as through the hook_menu()'s file property. If your module introduces hooks of its own, consider implementing hook_hook_info() to allow other modules' hook implementations to be autoloaded.

Comments

Needs to be updated?

I think this needs to be updated to reflect that the registry is only for classes now. But I don't know the best practices, so I'll refrain.

Actually, I think...

I think it was totally scrapped, so probably this page should be archived/deleted.

no, there is still a

no, there is still a registry.inc that stores the names of all classes and interfaces for autoloading.

---
Work: Acquia

I think the 4th paragraph is

I think the 4th paragraph is bumped to D8/never though, so that should be axed at least.

Page status

About this page

Drupal version
Drupal 7.x
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.