RE : [SMARTY] [Smarty] PHP Error Reporting E_ALL
| From: | Christopher Rousseau | Date: | Fri, 31 Oct 2003 16:46:47 +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-10483@lists.php.net to get a copy of this message | ||
I'm doing the same as you and prefere to not have message such like
that.
But I use another way to do it:
All my test are doing in the logic template (php) and all the variable I
use inside the presentation template are alway assigned. The logic
template assign an empty variable if necessary.
The way you propose, it will add more process because you will test
EVERY time if the variable exist.
If you still want to do like that try to add () around it to obtain this
output:
(isset($this->_tpl_vars['$var_name']) ? $this->_tpl_vars['$var_name'] :
'')
I did have the same probleme with constant in smarty and if statement,
and resolve it by enclosing all my constant with () because smarty
replace constante by the same type of code than your. It's a problem
related with priority of operators.
-----Message d'origine-----
De : Thorsten Suckow-Homberg [mailto:ts@siteartwork.de]
Envoyé : vendredi 31 octobre 2003 00:31
À : smarty-general@lists.php.net
Objet : [SMARTY] [Smarty] PHP Error Reporting E_ALL
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']['$sect
ion_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