Re: smarty_mod_default and number zero
| From: | Monte Ohrt | Date: | Tue, 20 Nov 2001 15:10:50 +0000 |
| Subject: | Re: smarty_mod_default and number zero | ||
| References: | 1 | Groups: | php.smarty.general |
| Request: | Send a blank email to php-smarty-general+get-1988@lists.php.net to get a copy of this message | ||
I don't think treating "0" as empty would be the way you want this
function to work in most cases, but we can add an optional second
parameter to allow this behavior, and keep backward compatability:
{$title|default:"no title":true}
function smarty_mod_default($string, $default="",$zero_empty=false) {
...
}
Rene-Marc Simard wrote:
>
> 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
>
> ---
> You are currently subscribed to smarty as: monte@ispi.net
> To unsubscribe send a blank email to $subst('Email.Unsub')
> Visit Smarty's homepage at
> http://www.phpinsider.com/php/code/Smarty/
--
Monte Ohrt <monte@ispi.net>
http://www.ispi.net/