2

I am having problems making my module work.

module_name.info

...

files[] = module_name.module
files[] = module_name.pages.inc
files[] = module_name.admin.inc
files[] = module_name.install
files[] = module_name.controller.inc

...

But when the module should access to functions stored on module_name.module I get this error, saying the function has not been found.

Warning: call_user_func_array() expects parameter 1 to be a valid callback....not found or invalid function name in call_user_func_array() (line 517 of /path_to_modules/module_name/includes/menu.inc). =>

If I put the functions on the module_name.module file, everything works fine. Apparently is not loading the files[]

Update: I've followed this example: https://github.com/LearningDrupal7Development/artwork

Any idea?

1 Answer 1

5

files[] is only used to register files containing classes or interfaces, not functions. The docs explain it well:

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, like so:

name = Really Neat Widget
...
files[] = example.test

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.

emphasis mine. Unless you have classes in any of those files (including the .module and .install file) that you want to be auto-loaded, you don't need an entry for them in the .info file; it just won't do anything.

If you need to pull other files in you can use module_load_include(), e.g.

module_load_include('inc', 'module_name', 'module_name.controller');
3
  • 1
    I have read the documentation before, and although I knew files[] would load classes, it is not really clear that it will not load functions. (I just tested it and you are absolutely correct!) I know that many modules list files which do not contain classes (eg. webform: views/webform.views.inc) and I never realized that those listings were pointless. I think the documentation should be altered to state that the files[] directive is ONLY to load class or interface descriptions. Thank you for pointing this out.
    – Triskelion
    Commented Jun 9, 2013 at 1:53
  • Hi Clive, thanks for your answer. I have updated the question with more info. I've been following a module tutorial. That tutorial doesn't seem to be using module_load_include. Is the tutorial wrong then? Thanks!! Commented Jun 9, 2013 at 11:24
  • It's not wrong as such, misleading might be a better word. The only file that needs to be added through the .info file is the controller.inc file, as that's the only one that contains a class.
    – Clive
    Commented Jun 9, 2013 at 11:35

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.