$smarty.const.CONSTANT operator precedence bug
| From: | Patrick Emond | Date: | Mon, 03 Mar 2003 19:41:42 +0000 |
| Subject: | $smarty.const.CONSTANT operator precedence bug | ||
| Groups: | php.smarty.dev | ||
| Request: | Send a blank email to php-smarty-dev+get-887@lists.php.net to get a copy of this message | ||
Hello all,
I've noticed what I believe is a (small) bug. If the following is
written in a Smarty template:
{if 0 == ($smarty.section.row.index % $smarty.const.SOME_CONST)}
It's compiled as:
if (0 == ( $this->_sections['row']['index'] % defined('SOME_CONST')
?
SOME_CONST : null )):
But since '%' has a higher precedence then '?' php processes
"$this->_sections['row']['index'] %
defined('SOME_CONST'}" then
processes the "?" operator (thus causing the incorrect behavior).
[IE: "a % b ? c:d" is equivalent to "(a % b) ? c:d" not "a % (b ?
c:d)"]
A quick template fix would be to put parenthesis around the
$smarty.const.SOME_CONST. Alternatively this can also be fixed in the
compiler by adding parenthesis around the string created on line 1801 of
Smarty_Compiler.class.php (version 2.4.2), but I can't really say how
that will harm some other part of the smarty compiler.
Cheers,
Patrick