Why am I urged to include my source files via files[] instead of using include_once?

drupal.stackexchange https://drupal.stackexchange.com/questions/11878

  •  16-10-2019
  •  | 
  •  

Question

What is the reason of using the .info file to declare the files used from the module, instead of including them at runtime?

Was it helpful?

Solution

From Writing .info files (Drupal 7.x):

Drupal now supports a dynamic-loading code registry. To support it, all modules must now declare any code files containing class or interface declarations in the .info file (...). When a module is enabled, Drupal will rescan all declared files and index all the classes and interfaces that it finds. Classes will be loaded automatically by PHP when they are first accessed.

So it only makes sense to add a file to the files[] array, if that file contains declarations of classes or interfaces and is not included manually (e.g. by calling module_load_include()).

Licensed under: CC-BY-SA with attribution
Not affiliated with drupal.stackexchange
scroll top