variable_get() employs caching which is useful most of the time but can be detrimental when it's important to guarantee the newest value from the database. Providing a third boolean argument to variable_get() could make it query the database and retrieve the latest value.

(Currently, the only way to get a new value with variable_get() is to clear the entire variable cache with cache_clear_all().)

Comments

JirkaRybka’s picture

Version: 5.1 » 7.x-dev

This might be also useful for install.php, where a variable needs to be retrieved before matching bootstrap (currently done directly via local implementation of a query).

But otherwise, new features (API-changing like this, especially) should go into 7.x as far as I know.

clouserw’s picture

Adding an optional third parameter is a pretty small change. We're not talking about objects that can be extended, so we shouldn't be conflicting with any overloaded methods. I'm suggesting the signature be:

function variable_get($name, $default, $cached=true)

which shouldn't break or change any existing code. I'd recommend targeting 6.x-dev (but I'm not as familiar with your versioning, so I'll just leave it at that).

Thanks.

marcingy’s picture

Version: 7.x-dev » 8.x-dev
swentel’s picture

Status: Active » Closed (won't fix)

variable_get() is gone in D8, replaced by the configuration system, which allows for all sorts of contexts to grab a setting (e.g. context free to get the default/original variable)