Re: 'default'-modifier causes a php-notice

From: Date: Wed, 12 Mar 2003 00:24:06 +0000
Subject: Re: 'default'-modifier causes a php-notice
Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-944@lists.php.net to get a copy of this message
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? Bye... Nagger PS: Am I the onlyone setting error_reporting to E_ALL?

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