Drupal - Global variable, visible only inside the module

If you use the same global variable, its value is shared between all the enabled modules because global variables are globals by definition. Every PHP file that is loaded will see the same global variables, such as the global $user that is used from Drupal for the account of the currently logged-in user.

The same is true if you use constants defined with define(); they are global, and two modules cannot define the same constants. Try defining the REQUEST_TIME in Drupal 7, with define('REQUEST_TIME, 'test'): You will get an error, as the same constant is already defined from Drupal (see REQUEST_TIME).

The same is true for Drupal variables defined with variable_set(). Every module that is using variable_set($name, $value) (where $name has the same value for all the modules) is setting the same variable.

Even if you would be using &drupal_static($name, $value) in different modules, the modules will be altering the same static variable.

I would rather use a constant defined with define(), but every module needs to use a different constant.
See the Drupal coding standards about naming conventions.

Tags:

7