[drupal-devel] Getting rid of global variables

Khalid B kb at 2bits.com
Fri Sep 30 13:25:25 UTC 2005


I like the idea in general.

Better change it to be :

drupal_set($key, $value = NULL, $module='system', $force = FALSE)

This way we just have key and value being mandatory. This will be
useful for widespread variables like $user for example.

On 9/30/05, Karoly Negyesi <karoly at negyesi.net> wrote:
> 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