RE: [SMARTY-DEV] RE: [SMARTY] php5 Iterators.
[email protected] (David Zülke)
| Newsgroups | php.smarty.dev |
|---|---|
| Organization | bitXtender GbR |
| Message-ID | <[email protected]> |
We _could_ count the number of properties in the array using count((array)$foo); I can't see any way of resolving item count, position, first/last etc from an iterator. People who're using iterators are most likely aware of this and can work around it or just live with that "problem". You're right, it's time to tackle this one, but I also think the time might have come to do a complete PHP5 rewrite of Smarty. I'd be happy to help. David > -----Original Message----- > From: boots [mailto:[email protected]] > Sent: Monday, January 24, 2005 11:19 AM > To: David Zülke; 'Mark Rogers'; [email protected] > Cc: 'boots' > Subject: RE: [SMARTY-DEV] RE: [SMARTY] php5 Iterators. > > --- David Z|lke <[email protected]> wrote: > > Couldn't we just change the array casting so it is only performed if > > the variable is _not_ an object? > > > > foreach($object as $key => $ value) {} > > is the same as > > foreach((array)$object as $key => $ value) {} > > > > Both will loop over the properties of an object. > > > > It will also work in PHP5. If there's an iterator defined, PHP will > > use it, if not, it will loop over the properties just like in the > good > > old times. > > This reminds me of some correspondance from last year -- back in July > messju raised this issue with Monte and I and at the end of it the > following was proposed: > > $_from =& $this->_tpl_vars['list']; // by ref for php4 BC > if ( count($_from) && ( is_array($_from) || is_object($_from) ) ): > foreach ($_from as $this->_tpl_vars['cell']): > ... > endforeach; > else: > // err > endif; > unset($_from); > > At the time, messju was against the =& so as to not raise the > possiblity of subtle bugs. Otherwise, we were all in agreement that it > was a reasonable approach. As I still haven't really delved into PHP5, > I am in no position to understand the minute issues that might arise. > My understanding is that there is a difficulty with count and the need > for certain interfaces to be implemented for this to work properly for > objects. For example, Bok proposed a different solution > http://news.php.net/php.smarty.dev/2510 but messju pointed out some of > the issues that it raised: http://news.php.net/php.smarty.dev/2515 > > My only concern is that too much PHP5 specific code to check for > correctness gets inserted into the foreach procedure thereby hampering > PHP4 performance in any way. Otherwise, it seems like the time is > approaching where this needs to be addressed. > > xo boots > > -- > Smarty Development Mailing List (http://smarty.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >