Problem/Motivation
Module authors freely create hook and function names in the global namespace. When modules are allowed to contain underscores, this creates the possibility of name conflicts. For example, the webform module might define webform_layout_something(). There may be a module named webform_layout which too defines an identically-named "something" function. Both module authors believe they are acting in their own namespace.
This may not affect modules with unusual names, but there are dozens -- probably close to a hundred -- webform-related modules. As a webform maintainer, when I create a new function I fear creating a name conflict.
As a further complication certain global actions cannot be taken on webform_* for fear of unintended actions on modules which start with webform_. An example in Drupal 7 would be deleting configuration variables upon uninstall.
Proposed resolution
Require that new module projects avoid underscores in the "short name".
Remaining tasks
Adopt and document policy.
User interface changes
None.
API changes
None.
Reference
Current module naming documentation.
Comments
Comment #1
danchadwick commentedNo comments?
Here's a recent actual example: #2486765: Confusing replacements in email component caused by webform_clear module conflict.
Webform create a function called webform_clear_tokens. It turns out there is a webform_clear module. So webform's namespaced function gets called as webform_clear's implementation of hook_tokens. Much confusion ensues.
Comment #2
drunken monkeyI think the proper fix would be to change how hooks are derived – e.g., with a second underscore between module and hook name.
With all the existing modules with (as we see here) a lot of potential for conflicts, I don't think changing this now would really improve things by much. Or at least not by enough if you think of the aweful-to-read module names that would give us.
Comment #3
danchadwick commentedProbably true, but also probably too late, even for D8.
Well, most of those conflicts have already been caught. I think changing the policy for new modules would help, and would be backward compatible. If you can't figure out the word breaks without underscores, then I'd venture that the module name sucks.
webformconditionals
webformanonymous
entitycache
usermerge
Comment #4
tizzo commentedThe Drupal Technical Working Group has discussed this and we agree with #2 that the proper solution for Drupal 9 is #548470: Use something other than a single underscore for hook namespacing or something else that would make this moot. For Drupal versions 8 and prior, we feel that it would create too much inconsistency to introduce this as a new policy that would not be followed by thousands of existing modules.
On a personal note, I am very sympathetic to this issue as the original author of Webform Entity module which plagued me with namespace conflicts. For now we will close this issue with a “won’t fix”, but as the underlying problem of collision risk does continue to be an issue, we're open to seeing new issues filed with proposals for dealing with it in Drupal 7 and Drupal 8 that is less of a blunt instrument than banning all underscores.