Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53389 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 39421 invoked from network); 20 Jun 2011 11:48:11 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 11:48:11 -0000 Authentication-Results: pb1.pair.com header.from=robert@xarg.org; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=robert@xarg.org; spf=permerror; sender-id=unknown Received-SPF: error (pb1.pair.com: domain xarg.org from 209.85.220.170 cause and error) X-PHP-List-Original-Sender: robert@xarg.org X-Host-Fingerprint: 209.85.220.170 mail-vx0-f170.google.com Received: from [209.85.220.170] ([209.85.220.170:40617] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id DE/0B-34681-A733FFD4 for ; Mon, 20 Jun 2011 07:48:11 -0400 Received: by vxi39 with SMTP id 39so849660vxi.29 for ; Mon, 20 Jun 2011 04:48:08 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.118.146 with SMTP id v18mr1734010vcq.239.1308570488168; Mon, 20 Jun 2011 04:48:08 -0700 (PDT) Received: by 10.220.45.196 with HTTP; Mon, 20 Jun 2011 04:48:08 -0700 (PDT) X-Originating-IP: [92.225.216.141] In-Reply-To: References: Date: Mon, 20 Jun 2011 13:48:08 +0200 Message-ID: To: Derick Rethans Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=00221572697e1c60bb04a6234fe3 Subject: Re: [PHP-DEV] foreach() for strings From: robert@xarg.org (Robert Eisele) --00221572697e1c60bb04a6234fe3 Content-Type: text/plain; charset=ISO-8859-1 2011/6/20 Derick Rethans > 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 > --00221572697e1c60bb04a6234fe3--