Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Smarty 3.1.7 for loop bug

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs
View previous topic :: View next topic  
Author Message
altendew
Smarty Rookie


Joined: 07 Mar 2008
Posts: 19

PostPosted: Tue Jan 10, 2012 4:46 am    Post subject: Smarty 3.1.7 for loop bug Reply with quote

I noticed a bug with the for loop.

The following works
{for $i = 1000; $i >= 1; $i --}

The following does not work

{for $i = 1000 to 1}

The for loop does not support going backwards when just specifying "to"
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jan 10, 2012 2:54 pm    Post subject: Reply with quote

try with step=-1
Back to top
View user's profile Send private message Visit poster's website
altendew
Smarty Rookie


Joined: 07 Mar 2008
Posts: 19

PostPosted: Tue Jan 10, 2012 3:27 pm    Post subject: Reply with quote

That worked, but if that is missing should it be expected behavior to work that way?

This use to work in the Smarty3.0rc3 and I had to change around on a lot of websites to get it to work.
Back to top
View user's profile Send private message
altendew
Smarty Rookie


Joined: 07 Mar 2008
Posts: 19

PostPosted: Tue Jan 10, 2012 3:30 pm    Post subject: Reply with quote

I compared the versions and see this code was replaced:

Smarty3.0rc3
Code:

            if (isset($_attr['step'])) {
                $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
            } else {
                $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = ($_attr[to] - ($_statement[value]) < 0) ? -1 : 1;";
            }



With this

Smarty3.1.7
Code:

            if (isset($_attr['step'])) {
                $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = $_attr[step];";
            } else {
                $output .= "\$_smarty_tpl->tpl_vars[$_statement[var]]->step = 1;";
            }


Is there a reason the method for solving the step (if not set) was taken out and just replaced with 1?
Back to top
View user's profile Send private message
mohrt
Administrator


Joined: 16 Apr 2003
Posts: 7368
Location: Lincoln Nebraska, USA

PostPosted: Tue Jan 10, 2012 4:44 pm    Post subject: Reply with quote

uwe can probably answer this better, but it is probably a better idea to not assume a step value based on the from->to values. No different than php for(), there is no assumption of a negative step value, you have to supply it. for consistency, step is always 1 if not supplied.
Back to top
View user's profile Send private message Visit poster's website
U.Tews
Administrator


Joined: 22 Nov 2006
Posts: 5068
Location: Hamburg / Germany

PostPosted: Fri Jan 13, 2012 1:12 pm    Post subject: Reply with quote

We did have a couple of issues determining the step value automatically from the from->to values. Remember the later can be variables.

For that reasion the code was changed.
Back to top
View user's profile Send private message
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> Bugs All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP