declared variables should be moved into init hook

kenorb - December 19, 2008 - 22:46
Project:Feedjit
Version:6.x-1.x-dev
Component:Code
Category:bug report
Priority:normal
Assigned:Unassigned
Status:active
Description

On the beginning of the module file there are variables which are declared directly in file, which using t() function.
It's not good idea to to that.

global $_feedjit_color_names, $_feedjit_schemes;
$_feedjit_color_names = array('bc', 'tc', 'brd1', 'lnk', 'hc');
$_feedjit_schemes = array( // in color.module format
  '#FFFFFF,#494949,#336699,#494949,#336699' => t('Feedjit Neutral'),
  '#E8F6BE,#666666,#C4C4C4,#666666,#7F7F7F' => t('Feedjit Green'),
...
);

During loading the files, module making mysql access and slowing down loading process and some functionality can be not available in this time (like caching, other handling, etc).
It's better to move this code into init or boot hook.

Like:

/**
* Implementation of hook_init().
*/
function feedjit_init() {
    global $_feedjit_color_names, $_feedjit_schemes;
    $_feedjit_color_names = array('bc', 'tc', 'brd1', 'lnk', 'hc');
...
}

#1

lyricnz - December 22, 2008 - 02:35

True. If I was going to start messing around with this module, I should probably add:

- fetch colorsets in a hook, allowing other modules to add new alternatives

- allow user-configurable colorsets

 
 

Drupal is a registered trademark of Dries Buytaert.