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
  •  | 
  •  

سؤال

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

هل كانت مفيدة؟

المحلول

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()).

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى drupal.stackexchange
scroll top