Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53401 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 63473 invoked from network); 20 Jun 2011 13:11:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 13:11:57 -0000 Authentication-Results: pb1.pair.com smtp.mail=leedavis81@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leedavis81@gmail.com; sender-id=pass; domainkeys=bad Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.83.170 as permitted sender) DomainKey-Status: bad X-DomainKeys: Ecelerity dk_validate implementing draft-delany-domainkeys-base-01 X-PHP-List-Original-Sender: leedavis81@gmail.com X-Host-Fingerprint: 74.125.83.170 mail-pv0-f170.google.com Received: from [74.125.83.170] ([74.125.83.170:35239] helo=mail-pv0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 23/8F-34681-D174FFD4 for ; Mon, 20 Jun 2011 09:11:57 -0400 Received: by pvh10 with SMTP id 10so3794569pvh.29 for ; Mon, 20 Jun 2011 06:11:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc:content-type; bh=VKUfJidtfaUaDjyKmWbyYtlsLTd/EaeOQ0foA5HlakI=; b=G8SGKE2f+5JcvYy0v0G1m+MfFh62pSILujDRWWqnl3uYfU5dh54aOmifFgSzzwVyV8 jAAE4eXvWFLn//9Ww5auIc9wi5HjQLuZUHMUiXtCl41e5tpujA1YNa4RLNwwTZAD7H7p cOSfKUVZ4q9cmHQMD7EyHjYGIYsL6x/stxacw= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=FQm7GjLGKbBxFs1NXz+Hq8fKAhfTKoqyHaJWt9txaQgK0i7OpFp4NMU02bSNsteuOx cSBJYfBScRkvq5qACNtd1Wx0ba9Lobj9BoVUI0K57NWzwKnkGDueijIs40dW6OE7tMO3 ASZHFNOlxGatFxrm1I7073nzGeS1fMsiiQW5A= MIME-Version: 1.0 Received: by 10.142.163.10 with SMTP id l10mr743326wfe.164.1308575514388; Mon, 20 Jun 2011 06:11:54 -0700 (PDT) Received: by 10.142.224.18 with HTTP; Mon, 20 Jun 2011 06:11:54 -0700 (PDT) In-Reply-To: References: Date: Mon, 20 Jun 2011 14:11:54 +0100 Message-ID: To: Robert Eisele Cc: internals@lists.php.net Content-Type: multipart/alternative; boundary=000e0cd32a58b26af604a6247a3c Subject: Re: [PHP-DEV] foreach() for strings From: leedavis81@gmail.com (Lee davis) --000e0cd32a58b26af604a6247a3c Content-Type: text/plain; charset=ISO-8859-1 I think this would be quite a useful feature, and am In favor of it. However, I think caution should be taken when shifting array utilities out of their remit and allowing them to manipulate / traverse other data types. You may see the floodgates opening for more request to adapt array functions for other uses. Say for instance.. Could we also use current(), next() and key() for iteration of strings? $string = 'string'; while ($char = current($string)) { echo key($string) // Would output the offset position I assume 0,1,2 etc?? echo $char // outputs each letter of string next($string); } Lee On Mon, Jun 20, 2011 at 12:27 PM, 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 > --000e0cd32a58b26af604a6247a3c--