Drupal - How does Drupal handle autoloading of classes?

All files listed in .info files are parsed when modules are rebuild (Only changed/new files in that list are, for performance reasons).

That information is then stored in the {registry} and {registry_files} tables. So if you want to get all classes or those according to a given naming pattern, you can query those tables.


Drupal maintains a code registry and uses it for its classes autoloader. To populate this registry with your module's classes, you should add their files to the files[] entry in it's .info file:

files[] = includes/Foo.inc
files[] = includes/Bar.inc

PHP's class autoloading will make sure that the parent class file is also loaded.

Credit to user pier-buyle for this answer, see his original answer here for the same question.

Hope that helps


spl_autoload_functions() returns the list of the autoload functions that have been registered with spl_autoload_register(). Drupal registers two autoload functions: one for the classes (drupal_autoload_class()), and one for the interfaces (drupal_autoload_interface()).

Both the functions use _registry_check_code(); using its code, you can write a function that lists all the classes implemented by Drupal 7 modules.

Tags:

7

.Info