I can't tell from the source for variable_get() for Drupal 6 whether it first looks for something in the variable table in the database, or the $conf array in settings.php.

Also, if I were to add something in some code to the $conf array, would I need to do anything in order for variable_get to see it?

global $conf;
$conf['myvalue'] = 'newvalue';

If 'myvalue' were set to 'oldvalue' in settings.php, then what would I need to do in order for $conf['myvalue'] to now return newvalue instead of oldvalue?


The function that is responsible for loading the values of the Drupal variables in memory is variable_init(), which executes the following code:

  if ($cached = cache_get('variables', 'cache')) {
    $variables = $cached->data;
  else {
    $result = db_query('SELECT * FROM {variable}');
    while ($variable = db_fetch_object($result)) {
      $variables[$variable->name] = unserialize($variable->value);
    cache_set('variables', $variables);

  foreach ($conf as $name => $value) {
    $variables[$name] = $value;

$conf, the value passed to the function from _drupal_bootstrap() is the array read from the settings.php file. The function that reads the configuration file is conf_init(), which is called from _drupal_bootstrap() before calling variable_init(). As you see in the code, the values read from the database are then overwritten with the values find in the $conf array.

Similar code is present in Drupal 7 (see drupal_bootstrap(), _drupal_bootstrap_configuration(), and _drupal_bootstrap_variables()).

The only way to use the value read from the database is to remove the value set in settings.php.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.