How do you like to define your module-wide variables in drupal 6?

Posted by sprugman on Stack Overflow See other posts from Stack Overflow or by sprugman
Published on 2010-04-07T19:33:39Z Indexed on 2010/04/07 19:53 UTC
Read the original article Hit count: 113

Filed under:
|

I'm in my module file. I want to define some complex variables for use throughout the module. For simple things, I'm doing this:

function mymodule_init() {
    define('SOME_CONSTANT', 'foo bar'); 
}

But that won't work for more complex structures. Here are some ideas that I've thought of:

global:

function mymodule_init() {
    $GLOBALS['mymodule_var'] = array('foo' => 'bar');
}

variable_set:

function mymodule_init() {
    variable_set('mymodule_var', array('foo' => 'bar'));
}

property of a module class:

class MyModule {
    static $var = array('foo' => 'bar');
}

Variable_set/_get seems like the most "drupal" way, but I'm drawn toward the class setup. Are there any drawbacks to that? Any other approaches out there?

© Stack Overflow or respective owner

Related posts about drupal

Related posts about best-practices