Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53431 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 42589 invoked from network); 20 Jun 2011 16:57:39 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jun 2011 16:57:39 -0000 Authentication-Results: pb1.pair.com header.from=truth@proposaltech.com; sender-id=softfail Authentication-Results: pb1.pair.com smtp.mail=truth@proposaltech.com; spf=softfail; sender-id=softfail Received-SPF: softfail (pb1.pair.com: domain proposaltech.com does not designate 98.139.44.166 as permitted sender) X-PHP-List-Original-Sender: truth@proposaltech.com X-Host-Fingerprint: 98.139.44.166 nm16-vm0.access.bullet.mail.sp2.yahoo.com Received: from [98.139.44.166] ([98.139.44.166:41379] helo=nm16-vm0.access.bullet.mail.sp2.yahoo.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 7A/DE-34681-EFB7FFD4 for ; Mon, 20 Jun 2011 12:57:38 -0400 Received: from [98.139.44.105] by nm16.access.bullet.mail.sp2.yahoo.com with NNFMP; 20 Jun 2011 16:57:29 -0000 Received: from [98.139.44.68] by tm10.access.bullet.mail.sp2.yahoo.com with NNFMP; 20 Jun 2011 16:57:29 -0000 Received: from [127.0.0.1] by omp1005.access.mail.sp2.yahoo.com with NNFMP; 20 Jun 2011 16:57:29 -0000 X-Yahoo-Newman-Id: 612698.55213.bm@omp1005.access.mail.sp2.yahoo.com Received: (qmail 27951 invoked from network); 20 Jun 2011 16:57:29 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1308589049; bh=FNXhBRDqXPdazn7dpET4hTaAXpVPk1lfZg33DgRW24U=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:Subject:From:To:In-Reply-To:References:Content-Type:Date:Message-ID:Mime-Version:X-Mailer:Content-Transfer-Encoding; b=YfhKv55dh4u7GKXpTM2XKlU73CQejSRUG33h0BZcdsAd2ecIXCDTfivc9gJh1nJqfRqOV/UhKpGQmoPCl9z7jyyQ+DsTh9tvrBILqQg/nQ4g0z34xPdvjoG4pDkB5TPZr/S2K3KSHW6CXuZUwOL+4jCYnbZk9cVHMecOIb7Y/H4= Received: from [192.168.2.102] (truth@208.127.5.147 with login) by smtp104.sbc.mail.ne1.yahoo.com with SMTP; 20 Jun 2011 09:57:28 -0700 PDT X-Yahoo-SMTP: jWG9jiaswBBOCHlPTWD9zJWRnNyiDJE- X-YMail-OSG: bAXZdxoVM1lHOcNDd8y6LIDSi3hHwrOh4lJTkIcbwdePkBG fUA.QR8GokOi3nQZeDSQz57E.wOw_meWbj7G3z8i0DfEBKsCn_iicuNql0H6 MXzM8gRpMZGx1k17HdoSn9aIeD30cfVJPuzSBuw1LiJAhWYwA0gR9PJmQ0kG _xZHLreAU9LLYBLU7_bMttGePfVpgXr1PspTH93p267B1ev4Qv0FQRA.z76e 1jP.IZ1Vrh1NuRnPUQO1m3dadXwsbPn1i8Yf6nRDU3mv.25izQugMyLHNZNM vgWv_SxU_bwy7dchffmPqpQUk6uy_Nr4OEc1Sp_joq8IGF1nOn6dT2Oekzz. qODGkKMWkPBC29m9_wGns.O58G6Z1NNyK5t7xk4FnvygHSA-- X-Yahoo-Newman-Property: ymail-3 To: internals@lists.php.net In-Reply-To: References: <1308584208.6296.9.camel@guybrush> <1308586150.6296.13.camel@guybrush> Content-Type: text/plain; charset="ISO-8859-1" Date: Mon, 20 Jun 2011 09:57:24 -0700 Message-ID: <1308589044.8394.27.camel@inspiron> Mime-Version: 1.0 X-Mailer: Evolution 2.30.1.2 Content-Transfer-Encoding: 7bit Subject: Re: foreach() for strings From: truth@proposaltech.com (Todd Ruth) Adding to John Crenshaw's list of reasons not to implicitly treat strings as arrays in foreach loops... Please keep in mind the following valid code: $s = 'hello'; foreach ((array)$s as $x) { var_dump($x); } The result is: string(5) "hello" That behavior can be handy. Hopefully, a BC break wouldn't occur if any of the string features currently being discussed are implemented. Without a BC break, having strings implicitly be treated as arrays in foreach loops will seem very strange in cases like the above. Iterators are nice. Having a "text_string_to_array" function would also be fine. For example: $s = 'hello'; foreach (text_string_to_array($s) as $x) { var_dump($x); } The result would be: string(1) "h" string(1) "e" string(1) "l" string(1) "l" string(1) "o" I don't know enough about the internals to say for sure, but perhaps text_string_to_array() could be implemented as creating a reference to the string that has a flag set that causes it to be allowed to be treated as an array. (A full conversion might be needed it were written to. For example, $a = text_string_to_array($s); $a[0] = 5; ) - Todd