Hello Drupal users!

I developed a module which has some submodules.
After that I pushed this module to the sandbox and used http://pareview.sh/ service to automatically get errors of the module.
But I've got a problem: there're a lot of "all functions should be prefixed with your module/theme name to avoid name clashes" errors.

Example of the error:

./typical_entity_example_3/typical_entity_example_3.install: all functions should be prefixed with your module/theme name to avoid name clashes. See http://drupal.org/node/318#naming

function typical_entity_example_3_schema() {
function typical_entity_example_3_modules_enabled($modules) {
function typical_entity_example_3_uninstall() {

List of other similar errors is here: http://pareview.sh/pareview/httpgitdrupalorgsandboxdragon6581991582git

What shall I do to fix this error. Is that a false error positive, or not?

Comments

jaypan’s picture

Not exactly an error, but a best practice. As of Drupal 7, there are no php namespaces, so prefixing your function names with the module name ensures that you will not have any collisions with other modules.
The only caveat here is that by prefixing your function names with your module name, you can sometimes create unintentional hook implementations that cause really hard to debug errors. As such, it can be better to prefix your functions with something unique, but not your module name.

Contact me to contract me for D7 -> D10/11 migrations.

dragon658’s picture

Hello Jaypan! Let me explain my problem again.

I have a module called "typical_entity_example_3".
This module has install file "typical_entity_example_3.install".
In this file, I have an implementation of hook_schema called "typical_entity_example_3_schema".
Everything works fine.

But http://pareview.sh/ service says that "typical_entity_example_3_schema" function "shall be prefixed with my module/theme name to avoid name clashes"!
I suppose that this is because "typical_entity_example_3" folder (folder of my module) is subfolder of "typical_entity_examples" folder.
"typical_entity_examples" is the parent module of "typical_entity_example_3" module.

The question: why http://pareview.sh/ service does show this error? What shall I do to hix it?

jaypan’s picture

If I understand your description of the problem, the error is on their site, not with your module. You have already correctly named your hook, that site isn't recognizing that fact.

Contact me to contract me for D7 -> D10/11 migrations.

dydave’s picture

Hi guys,

I just got the same issue while working on the validation of a module with a sub-module, in particular the following error:

All functions should be prefixed with your module/theme name to avoid name clashes. See http://drupal.org/node/318#naming

Basically, the name of the sub-module and all function names were not following the standards....
So I started investigating this issue further, found this post and a very helpful issue posted by @dragon658 with the answer at #2085529-1: False positives on submodule hooks:

all sub-modules within one project should be prefixed with the main module name to avoid name clashes. If somebody creates a page_manager project there will be fatal errors because of ctools ...

In other words, to bring back module in compliance with Coding Standards, the sub-module would have to be renamed to include the name of the main module. To keep the example of ctools from #2085529: False positives on submodule hooks, the correct answer would be that the page_manager module would have to be renamed: ctools_page_manager and all function/variable names updated accordingly.

So if we were to logically work on the example mentioned by @dragon658 in this post, the change that would most likely have to be made would be to rename the sub-module: "typical_entity_example_3" to "typical_entity_examples_3" (watch the "s" added), which would contain the name of the main module: "typical_entity_examples". Another possibility would be: typical_entity_examples_typical_entity_example_3 .... but I would assume this name would be a little bit too long.... but still, I would guess it should work.

Feel free to let us know if you would have any questions, comments, ideas, suggestions, issues or objections on any aspects in this comment or post in general, any further feedback would be greatly appreciated.

Thanks again to everyone for your feedback, questions, comments, ideas and answers.
Cheers!