Skip to: Site menu | Main content

WTF: Why is variable_get not pulling the value from the variable table?

What's that Feature?

When your code executes a variable_get what actually happens is that Drupal inspects the $conf global array variable to see if it contains an index with the variable name. It does NOT actually query the variable table.

The global variable is built from cached data. So, if you were having problems with $conf not containing the value that you verified was in the variable table, you could reasonably assume that you could fix the issue by making sure that you cleared caches to force it to be rebuilt. But, what if it STILL did not contain the value that's in the variable table?

Well, there is (at least) one other place where the $conf variable can be set: settings.php. Setting the variable in settings.php takes precedence over whatever is in the database.

So, the next time you can't seem to get the $conf variable to contain the value that you think it should contain, have a look through settings.php and see if it's being explicitly set there.

Thanks to Adrian Rollett for helping me out with this vexing problem when I simply could NOT figure out what was going on.

Edit: The Installation Guide contains a page that lists variables that can be set using the $conf array.

Great job on this Marc!

Great job on this Marc!

Credits: XWeb | Chris Herberte | Andreas Viklund