[drupal-devel] Getting rid of global variables

Adrian Rossouw adrian at bryght.com
Fri Sep 30 13:38:21 UTC 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

I proposed this a very long time ago ( > 2 years)

Calling it context_get and context_set ... i am opposed to having  
using the module in the function parameters though,
as it is better to be consistent with variable_get and variable_set  
(imo), and have coding guidelines dictate that you have to use
$module_ as the prefix.


On 30 Sep 2005, at 2:19 PM, Karoly Negyesi 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
>

- --
Adrian Rossouw
Drupal developer and Bryght Guy
http://drupal.org | http://bryght.com


-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (Darwin)

iD8DBQFDPT/EgegMqdGlkasRAvzDAKDg98368YzocBh8jsgSiZq8ksXuwwCgn2sZ
8WR7LctPwIYmtddN80k5MaU=
=ABGA
-----END PGP SIGNATURE-----



More information about the drupal-devel mailing list