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

Wim Leers bashratthesneaky at gmail.com
Thu May 3 10:04:28 UTC 2007


I personally see this as a viable use case, yes. It saves me another  
if-test. But my example wasn't quite accurate. Suppose you have a  
multiple select form item. You set the default to -1 for the settings  
page, and /then/ to NULL in your code. But probably you already  
figured that yourself.

I don't see how exactly this breaks my code? It doesn't break  
anything, it's pure convenience.

Wim

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

> Wim Leers wrote:
>> 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 :)
>
> So you break your code once the user saves the settings page. Do  
> you present this as a viable use case?
>
> Gabor



More information about the development mailing list