Upgrade Your Drupal Skills

We trained 1,000+ Drupal Developers over the last decade.

See Advanced Courses NAH, I know Enough

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.

Author: 
Original Post: 

About Drupal Sun

Drupal Sun is an Evolving Web project. It allows you to:

  • Do full-text search on all the articles in Drupal Planet (thanks to Apache Solr)
  • Facet based on tags, author, or feed
  • Flip through articles quickly (with j/k or arrow keys) to find what you're interested in
  • View the entire article text inline, or in the context of the site where it was created

See the blog post at Evolving Web

Evolving Web