Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53383 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 30347 invoked from network); 20 Jun 2011 11:27:09 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 11:27:09 -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:58092] helo=mail-vx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 8F/29-34681-C8E2FFD4 for ; Mon, 20 Jun 2011 07:27:09 -0400 Received: by vxi39 with SMTP id 39so838444vxi.29 for ; Mon, 20 Jun 2011 04:27:06 -0700 (PDT) MIME-Version: 1.0 Received: by 10.220.118.146 with SMTP id v18mr1727197vcq.239.1308569226404; Mon, 20 Jun 2011 04:27:06 -0700 (PDT) Received: by 10.220.45.196 with HTTP; Mon, 20 Jun 2011 04:27:06 -0700 (PDT) X-Originating-IP: [92.225.216.141] Date: Mon, 20 Jun 2011 13:27:06 +0200 Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=00221572697ee762aa04a6230324 Subject: foreach() for strings From: robert@xarg.org (Robert Eisele) --00221572697ee762aa04a6230324 Content-Type: text/plain; charset=ISO-8859-1 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. 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 think, adding features like this persuades the one or the other PHP user to upgrade to 5.4. Robert --00221572697ee762aa04a6230324--