Handling undefined variables

From: Date: Tue, 12 Mar 2002 19:32:32 +0000
Subject: Handling undefined variables
Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-3017@lists.php.net to get a copy of this message
I read with interest the thread on this subject that happened in January (http://marc.theaimsgroup.com/?t=101072708400001&r=1&w=2), but I noticed the problem is still there in the latest version of smarty. May I suggest the following patch? --- Smarty_Compiler.class.php Thu Feb 21 09:14:10 2002 +++ Smarty_Compiler.class.php Tue Mar 12 11:17:18 2002 @@ -1064,7 +1064,7 @@ $output = "\$this->_smarty_vars['$var_name']"; } } else { - $output = "\$this->_tpl_vars['$var_name']"; + $output = isset($GLOBALS[$var_name]) ? "\$this->_tpl_vars['$var_name']" : "''"; } foreach ($indexes as $index) { This isn't perfect... you could still have a variable existing that doesn't get assigned to the template vars and still generate a warning, but it would cut down the warnings quite a bit. Plus, it allows you to still use a mod_handler such as providing a default. Of course, I don't know much this would slow things down, but I thought I'd make the suggestion anyway. Thoughts?

« previous php.smarty.general (#3017) next »