Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53413 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 95609 invoked from network); 20 Jun 2011 15:25:31 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 15:25:31 -0000 Authentication-Results: pb1.pair.com smtp.mail=ilia@prohost.org; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=ilia@prohost.org; sender-id=pass Received-SPF: pass (pb1.pair.com: domain prohost.org designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: ilia@prohost.org X-Host-Fingerprint: 209.85.214.42 mail-bw0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:33016] helo=mail-bw0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D2/E4-34681-8666FFD4 for ; Mon, 20 Jun 2011 11:25:30 -0400 Received: by bwz18 with SMTP id 18so2843699bwz.29 for ; Mon, 20 Jun 2011 08:25:22 -0700 (PDT) MIME-Version: 1.0 Received: by 10.204.84.36 with SMTP id h36mr4244513bkl.76.1308583522074; Mon, 20 Jun 2011 08:25:22 -0700 (PDT) Received: by 10.204.57.81 with HTTP; Mon, 20 Jun 2011 08:25:21 -0700 (PDT) In-Reply-To: References: Date: Mon, 20 Jun 2011 11:25:21 -0400 Message-ID: To: Robert Eisele Cc: internals@lists.php.net Content-Type: text/plain; charset=ISO-8859-1 Subject: Re: [PHP-DEV] foreach() for strings From: ilia@prohost.org (Ilia Alshanetsky) As long as it works on a premise that a "string" is a byte array and each element represents 1 byte, +1 from me. On Mon, Jun 20, 2011 at 7:27 AM, 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. 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 >