2011/6/20 Derick Rethans <der...@php.net> > On Mon, 20 Jun 2011, Robert Eisele wrote: > > > foreach() has many functions, looping over arrays, objects and > implementing > > the iterator interface. I think it's also quite intuitive to use > foreach() > > for strings, too. > > > If you want to implement a parser in PHP, you have to go the way with for > + > > strlen + substr() or $x[$i] to address one character of the string. > > Yes, this sounds like a good addition to me. One question though, what > to do with an object that implements __toString() ? >
That's the question, maybe one must force __toString() via an explicit string-cast: foreach( (string) $obj as $k=>$v) > > > We could > > overdo the functionality of foreach() > > by implementing LVAL's, too, in order to access single bits but this is > > really uncommon, even if the way of thinking could be, that foreach() > gives > > a single attribute of each value, no matter > > if it's a complex object with the iterator interface or a primitive. What > do > > you think about this one? My point of view is, that foreach() is very > > useful, which was acknowledged by many ppl via the comments of my > article. > > I don't think we should do it for bits, as nothing in PHP really does do > anything with that. If you want to do stuff with bits, I think the > "bitset" package (http://pecl.php.net/package/Bitset) is the way > forwards. > yep, i totally agree. > > cheers, > Derick > > -- > http://derickrethans.nl | http://xdebug.org > Like Xdebug? Consider a donation: http://xdebug.org/donate.php > twitter: @derickr and @xdebug >