Re: [SMARTY] [Smarty] PHP Error Reporting E_ALL

From: Date: Fri, 31 Oct 2003 16:36:40 +0000
Subject: Re: [SMARTY] [Smarty] PHP Error Reporting E_ALL
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-10482@lists.php.net to get a copy of this message
what notices from the template do you wan't to retrieve if not the ones about undefined variables? why don't you just turn off E_NOTICES before you call fetch() or display() and turn them on again after that? On Fri, Oct 31, 2003 at 12:30:40AM +0100, Thorsten Suckow-Homberg wrote: > Hello List, > > for debugging and development purposes I have set my PHP error-reporting-level to E_ALL. > > Since smarty doesn't check if an index of the property "_tpl_vars" is set, I get > a lot of > "undefined index" errors. > > I don't want to check the vars in my script and would like to decide smarty wether an > index is set or not. > > I tried to do some changes to Smarty_Compiler::_parse_var() so the output-string would > look something like this: > > isset($this->_tpl_vars['$var_name']) ? $this->_tpl_vars['$var_name'] > : '' ; > > Unfortunately I then have problems with {if}-directives. > > Does someone have a hack/ clue/ advice here? > > Best regards > > Thorsten > > > P.S.: > > Based on Smarty 2.5 RC 2 my function _parse_var looks now like this. Feel free to use > this method and maybe give me a helping hand on this... > I hope my Newsreader won't f*** with the format... > > function _parse_var($var_expr) > { > preg_match('!(' . $this->_obj_call_regexp . '|' . > $this->_var_regexp . ')(' . > $this->_mod_regexp . '*)$!', $var_expr, $match); > > $var_ref = substr($match[1],1); > $modifiers = $match[2]; > > if(!empty($this->default_modifiers) && > !preg_match('!(^|\|)smarty:nodefaults($|\|)!',$modifiers)) { > $_default_mod_string = implode('|',(array)$this->default_modifiers); > $modifiers = empty($modifiers) ? $_default_mod_string : $_default_mod_string . '|' > . > $modifiers; > } > > // get [foo] and .foo and ->foo and (...) pieces > preg_match_all('!(?:^\w+)|' . $this->_obj_params_regexp . '|(?:' > . > $this->_var_bracket_regexp . ')|->\w+|\.\$?\w+|\S+!', $var_ref, $match); > > $indexes = $match[0]; > $var_name = array_shift($indexes); > > /* Handle $smarty.* variable references as a special case. */ > if ($var_name == 'smarty') { > /* > * If the reference could be compiled, use the compiled output; > * otherwise, fall back on the $smarty variable generated at > * run-time. > */ > if (($smarty_ref = $this->_compile_smarty_ref($indexes)) !== null) { > $output = "isset($smarty_ref) ? $smarty_ref"; > } else { > $var_name = substr(array_shift($indexes), 1); > $output = "\$this->_smarty_vars['$var_name']"; > } > } else { > /*@*/ $output = > "isset($"."this->_tpl_vars['$var_name']"; > //$output = "\$this->_tpl_vars['$var_name']"; > } > > /*@*/ $iTmpCount = 0; > > foreach ($indexes as $index) { > > /*@*/ $iTmpCount++; > > if ($index{0} == '[') { > $index = substr($index, 1, -1); > if (is_numeric($index)) { > $output .= "[$index]"; > } elseif ($index{0} == '$') { > $output .= "[\$this->_tpl_vars['" . substr($index, 1) . > "']]"; > } else { > $parts = explode('.', $index); > $section = $parts[0]; > $section_prop = isset($parts[1]) ? $parts[1] : 'index'; > /*@*/ $output .= > "[\$"."this->_sections['$section']['$section_prop']] ) ? > > $"."this->_tpl_vars['$var_name'][\$"."this->_sections['$section']['$section_prop']]"; > } > } else if ($index{0} == '.') { > if ($index{1} == '$') > $output .= "[\$this->_tpl_vars['" . substr($index, 2) . > "']]: ''"; > else > $output .= "['" . substr($index, 1) . "']: > ''"; > } else if (substr($index,0,2) == '->') { > if(substr($index,2,2) == '__') { > $this->_syntax_error('call to internal object members is not allowed', > E_USER_ERROR, > __FILE__, __LINE__); > } elseif($this->security && substr($index,2,1) == '_') { > $this->_syntax_error('(secure) call to private object member is not allowed', > E_USER_ERROR, __FILE__, __LINE__); > } > $output .= $index; > } elseif ($index{0} == '(') { > $index = $this->_parse_parenth_args($index); > $output .= $index; > } else { > $output .= $index; > } > } > > /*@*/if ($iTmpCount == 0) { > $output .= ") ? $"."this->_tpl_vars['$var_name'] : > ''"; > } > > $this->_parse_modifiers($output, $modifiers); > > return $output; > } > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

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