Re: [SMARTY-DEV] Re: 'default'-modifier causes a php-notice

From: Date: Wed, 12 Mar 2003 21:52:48 +0000
Subject: Re: [SMARTY-DEV] Re: 'default'-modifier causes a php-notice
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-949@lists.php.net to get a copy of this message
On Wed, Mar 12, 2003 at 01:24:06AM +0100, Nagger wrote: > Hi... > > I'm getting a php-notice when I use a modifier on an undefined variable. > That happens of course also on the "default"-modifier. But especially with > "default" it should not. > > {$foo|default:"nothing"} is compiled to > $this->_run_mod_handler('default', true, > $this->_tpl_vars['foo'],'nothing'); > > Because $this->_tpl_vars['foo'] isn't set, php reports a notice :( > > I know I can change my error_reporting or use {if > isset($foo)}{$foo}{else}nothing{/if}, but thats bad. > I think smarty/"default" should handle that. > > My suggestion is: > adding in "smarty_compiler.class.php" function "_parse_modifiers" something > like that: > > if ($modifier_name=='default') > $output = "isset($output)?$output:NULL"; > > With this change smarty would compile a 'default'-modifier to: > $this->_run_mod_handler('default', > true,isset($this->_tpl_vars['foo'])?$this->_tpl_vars['foo']:NULL, > 'nothing'); > > It's easy and no other behavior is changed, even the modifier.default.php > itself cannot recognize the change. > But it's a little bit dirty because 'default' is now half a built-in command > and half a plugin, but I cannot see another solution. > > Additionally you can leave the if(...) and only add $output = > "isset($output)?$output:NULL";. Then no modifier call is reporting a > php-notice anymore. Again no other behavior is changed (except the compiled > code is getting a little bit bigger and php has to perform a isset-check on > any call of a modifier). > > What do you think? i don't know if smarty proclaims to be notice-free in all circumstances. if so, another possible solution would be to make "default" a fully internal modifier or to make all modifier-calls silent by prepending an @ before the method call. > Bye... > Nagger > > PS: Am I the onlyone setting error_reporting to E_ALL?

« previous php.smarty.dev (#949) next »