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

foreach and php5 iterators problem & solution

 
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 -> Smarty Development
View previous topic :: View next topic  
Author Message
mensi
Smarty n00b


Joined: 29 Jun 2004
Posts: 4
Location: Switzerland -> Zug

PostPosted: Tue Jun 29, 2004 12:59 am    Post subject: foreach and php5 iterators problem & solution Reply with quote

I noticed that the current parsing of the {foreach} function casts the from parameter to an array so that it's impossible to use php5's iterators on objects.

A quick and perhaps dirty workaround for this is to change Smarty_Compiler.class.php:1168
from:
[php:1:bad303cb1b]$output .= "if (count(\$_from = (array)$from)):\n";[/php:1:bad303cb1b]
to [php:1:bad303cb1b]$output .= "if (is_object(\$_from = $from) || count(\$_from = (array)$from)):\n";[/php:1:bad303cb1b]

that will fix it only if you don't use the name= attribute as it needs the total count of items determined by count(), but I think you won't need that in connection with iterators...

would be nice if you could take care of this in the next release...
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 -> Smarty Development 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