Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53388 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 38032 invoked from network); 20 Jun 2011 11:44:46 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 11:44:46 -0000 Authentication-Results: pb1.pair.com header.from=derick@php.net; sender-id=unknown Authentication-Results: pb1.pair.com smtp.mail=derick@php.net; spf=unknown; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain php.net does not designate 82.113.146.227 as permitted sender) X-PHP-List-Original-Sender: derick@php.net X-Host-Fingerprint: 82.113.146.227 xdebug.org Linux 2.6 Received: from [82.113.146.227] ([82.113.146.227:53857] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 83/CA-34681-EA23FFD4 for ; Mon, 20 Jun 2011 07:44:46 -0400 Received: from localhost (xdebug.org [127.0.0.1]) by xdebug.org (Postfix) with ESMTPS id 4E399DE13E; Mon, 20 Jun 2011 12:44:43 +0100 (BST) Date: Mon, 20 Jun 2011 12:44:43 +0100 (BST) X-X-Sender: derick@whisky To: Robert Eisele cc: internals@lists.php.net In-Reply-To: Message-ID: References: User-Agent: Alpine 2.02 (DEB 1266 2009-07-14) MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Subject: Re: [PHP-DEV] foreach() for strings From: derick@php.net (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() ? > 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. cheers, Derick -- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug