Re: [SMARTY-DEV] $smarty.const.CONSTANT operator precedence bug

From: Date: Mon, 03 Mar 2003 20:26:47 +0000
Subject: Re: [SMARTY-DEV] $smarty.const.CONSTANT operator precedence bug
References: 1  Groups: php.smarty.dev 
Request: Send a blank email to php-smarty-dev+get-888@lists.php.net to get a copy of this message
On Mon, Mar 03, 2003 at 07:41:42PM +0000, Patrick Emond wrote: > 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. this should be fixed in CVS where $smarty.const.SOME_CONST is compiled to @constant("SOME_CONST") > Cheers, > Patrick have fun messju

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