Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53394 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 46977 invoked from network); 20 Jun 2011 12:07:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 12:07:53 -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:57380] helo=xdebug.org) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 72/9C-34681-8183FFD4 for ; Mon, 20 Jun 2011 08:07:52 -0400 Received: from localhost (xdebug.org [127.0.0.1]) by xdebug.org (Postfix) with ESMTPS id 86DFDDE13E; Mon, 20 Jun 2011 13:07:48 +0100 (BST) Date: Mon, 20 Jun 2011 13:07:48 +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: > 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) That's a sensible thing indeed. We just need to make sure we document this with an example and a test then. cheers, Derick -- http://derickrethans.nl | http://xdebug.org Like Xdebug? Consider a donation: http://xdebug.org/donate.php twitter: @derickr and @xdebug