[development] low hanging fruit for Drupal 6: variable defaults

Wim Leers bashratthesneaky at gmail.com
Thu May 3 09:44:12 UTC 2007

One use case is: on the settings page you set the default to a  
certain value, for example an empty string. But elsewhere in your  
code, you set the default to NULL, because then you can just do:

	$var = variable_get('some_var', NULL);
	foreach ($var as $key => $value) { ..}

without having to check if $var is the empty string. Because using  
NULL will immediately end the foreach loop and an empty string would  
generate an error.
Simple use case, but again a bit shorter!

I'll do this one :)


On May 3, 2007, at 11:19 , Gabor Hojtsy wrote:

> Gerhard Killesreiter wrote:
>>> Have fun with naming it hook_settings(), as far as I see, it is an
>>> appropriate name, and not taken at the moment :) So Drupal can do a
>>> module_invoke_all() on hook_settings() and collect defaults to all
>>> variables from the modules defining them. It gets easier and  
>>> shorter to
>>> use variables:
>>>   variable_get('my_fine_var');
>> We should however keep an optional second argument. I don't always  
>> use
>> the same second argument, and that's intentional.
> Erm, what you do if the user saves his settings into the db, so you  
> have one fixed value to work with? The use case of alternate  
> defaults for variables is not clear to me. Bbut I have nothing  
> against having that supported if you show a good use case, although  
> we would need to hammer people to update their code to use  
> hook_settings() as variable_get() will work as is without  
> modification in Drupal 6.
> Gabor

More information about the development mailing list