I've discovered a little bug that triggers under certain conditions.

If there exists a module named 'field', the following code in function field_file.inc:field_file_load()

foreach (module_implements('file_load') as $module) {
  $function = $module .'_file_load';
  $function($file);
}

calls the function named 'field_file_load', which ends up in an infinite recursive loop.

The obvious solution is inserting the following test:

foreach (module_implements('file_load') as $module) {
  $function = $module .'_file_load';
  if ($function != 'field_file_load') {
    $function($file);
  }
}

which prevents unwanted recursive calls.

A simple test that allows this module to be deployed into any environment, even in the presence of a module named 'field'. Of course, function field_file_load() (if defined) in module 'field' won't be called by this code, but I think PHP would complain earlier anyway for the double function definition (the only solution is to rename the function).

BTW, this actually happened, it's not a made-up example. 'field' is not a great name for a locally developed module, granted, but the point still holds.

Comments

quicksketch’s picture

Hm, interesting. I'm not sure we'll change this since "field" is a required, reserved module in Drupal 7. FileField is also in Drupal 7 core and this particular set of functions has been renamed (field_file_load() is just file_load() in Drupal 7).

TheMule’s picture

Well if the code has already changed in 7, there's no reason not to fix it in 6. Also the change seems quite trivial and Obviously Right (TM). Renaming the function as file_load() works as well (I haven't checked how many callers need to be fixed tho).

quicksketch’s picture

Oh we certainly can't change the name in Drupal 6, since file_load() is already a core Drupal function. What used to be field_file_load() is now file_load() in Drupal 7. We can't change the function name in Drupal 6 to something else either, since it would constitute a rather big (and unnecessary) API change. So my feeling right now is sort of a "just don't do that" approach when naming your custom modules.

quicksketch’s picture

Status: Active » Fixed

Eh, well the small IF statement isn't going to hurt I suppose, I've added it as recommended above.

quicksketch’s picture

Title: Possible function name clash » Possible function name clash with field_file_load()

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.