[drupal-devel] Getting rid of global variables

Karoly Negyesi karoly at negyesi.net
Fri Sep 30 12:18:21 UTC 2005


Hi!

global variables are hard to debug and error prone. Let's make it explicit:

drupal_set($module, $key, $value = NULL, $force = FALSE) {
   static $storage;
   if ($value || $force) {
     $storage[$module][$key] = $value;
   }
   return $storage[$module][$key];
}

drupal_get($module, $key) {
   return drupal_set($module, $key);
}

$force is useful when you want to set to NULL ie. delete a value.

If we can't find a revelant module for a core global value, we can use  
'system'.

Regards

NK



More information about the drupal-devel mailing list