Submitted by zzolo on 2010, February 17 - 9:22am
Update via Garrett Albright (see comments)
Just a quick tip for managing variables in a Drupal module. Please prefix your variables with your module name. For example:
variable_set('examplemodule_variable_name', 1234);
This ensures that another module won't override your variable, or your module won't do the same thing. Pretty simple. But what is also nice, is that you can clean up after your module a lot easier in the uninstall hook:
/**
* Implementation of hook_uninstall().
*/
function examplemodule_uninstall() {
// Get global variable array
global $conf;
// Find variables that have the module prefix
if (strpos($key, 'examplemodule_') === 0) { variable_del($key);
}
}
}
Please note that the above convention could cause problems if your module name is something like content_permissions and then the content module (CCK) defines a variable with a conflicting name. All the more reason to make your module names more unique and without underscores.