Re: [SMARTY] foreach on Iterator

From: Date: Mon, 21 Mar 2005 12:57:02 +0000
Subject: Re: [SMARTY] foreach on Iterator
References: 1  Groups: php.smarty.general 
Request: Send a blank email to php-smarty-general+get-12344@lists.php.net to get a copy of this message
Nothing at all. This behaviour has been know since the introduction of PHP5. At last check there was no plan to modify this behaviour for fear of breaking backwards compatibility. There was an unofficial patch floating around somewhere a few months back that preserved backwards compatibility and allowed you to use most of the foreach properties on an iterator (which would break by simply removing the cast). We were unable to come up with a perfect solution though due to the inability to count() the iterator at the time of writing. Perhaps this is something that can be revisited now. For the moment though it seems the only thing you can do is to modify the smarty library directly and then forcing yourself to remember your changes when you try to update smarty in the future. The recommended course of action is to wait for a fix to be committed to Smarty. -bok On Fri, 18 Mar 2005 14:32:12 +0100, Robin Ericsson <lobbin@localhost.nu> wrote: > Hi, > > I have a class which it using SPL and implements Iterator. It works when > I do it manually > > foreach($iterator as $key) { > } > > however, using {foreach from=$iterator item=key) generates the following > code: > > <?php if (count($_from = (array)$this->_tpl_vars['revisionIterator'])): > foreach ($_from as $this->_tpl_vars['revision']): > endforeach; endif; unset($_from); ?> > > You see the difference that Smarty really casts the object into an array > and therefore break my class. > > What can I do about it? > > -- > Robin Ericsson > http://robin.vill.ha.kuddkrig.nu/ > > -- > Smarty General Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Xnyo - http://xnyo.odynia.org/

« previous php.smarty.general (#12344) next »