[development] low hanging fruit for Drupal 6: variable defaults
Steven Wittens
steven at acko.net
Thu May 3 22:52:48 UTC 2007
> What happens if you have a variable whose default is TRUE but for
> which the
> set value is FALSE at the moment? I think in that case
>
> return $value ? $value : constant($name);
>
> is going to give you the constant instead of the perfectly-valid
> assigned value,
> isn't it?
I think Dries was more trying to illustrate a point. It is trivial to
change this so it doesn't suffer from this problem:
function variable_get($name) {
$value = db_query(...);
return db_num_rows($value) ? db_result($value) : constant($name);
}
We've introduced such automatic linking based on naming conventions
elsewhere in core too (e.g. menu argument handling, form api
callbacks, theme functions, etc), so this idea gets a bit +1 from me.
I always liked the idea of centralizing your defaults like this, but
I hated that it didn't save you from repeating the defined constant
everywhere.
Steven Wittens
More information about the development
mailing list