smarty_mod_default and number zero
| From: | Rene-Marc Simard | Date: | Tue, 20 Nov 2001 09:24:05 +0000 |
| Subject: | smarty_mod_default and number zero | ||
| Groups: | php.smarty.general | ||
| Request: | Send a blank email to php-smarty-general+get-1983@lists.php.net to get a copy of this message | ||
Since the function 'empty()' sees the number zero [0] as being empty, and since
people seem generally divided on the topic of whether such a behavior is really
a bug or a feature (feelin' like paraphrasing Rich Kulawiec :), what would the
Smarty community say if, for the add-on 'smarty_mod_default()', we tested
against an empty string instead? The pseudo-diff function, currently using
'empty()', would be:
function smarty_mod_default($string, $default="")
{
- if(empty($string))
+ if($string === '')
return $default;
else
return $string;
}
This way, if a string really equals 0, the default would not kick in. Nothing
earth shattering here, so I'm using my own default handler to circumvent the
issue. But if the powers that be feel like it, perhaps it could be added to the
snapshot?
René-Marc Simard
Popcorn Studios