Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:53564 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 94509 invoked from network); 24 Jun 2011 04:34:26 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Jun 2011 04:34:26 -0000 Authentication-Results: pb1.pair.com header.from=johncrenshaw@priacta.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=johncrenshaw@priacta.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain priacta.com designates 64.95.72.238 as permitted sender) X-PHP-List-Original-Sender: johncrenshaw@priacta.com X-Host-Fingerprint: 64.95.72.238 mx1.myoutlookonline.com Received: from [64.95.72.238] ([64.95.72.238:64488] helo=mx1.myoutlookonline.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/04-02049-0D3140E4 for ; Fri, 24 Jun 2011 00:34:25 -0400 Received: from mxout.myoutlookonline.com (localhost [127.0.0.1]) by mx1.myoutlookonline.com (Postfix) with ESMTP id 7393778D3BE; Fri, 24 Jun 2011 00:34:22 -0400 (EDT) X-Virus-Scanned: by SpamTitan at mail.lan Received: from HUB014.mail.lan (unknown [10.110.2.1]) by mx1.myoutlookonline.com (Postfix) with ESMTP id 1733978D38E; Fri, 24 Jun 2011 00:34:22 -0400 (EDT) Received: from MAILR001.mail.lan ([10.110.18.27]) by HUB014.mail.lan ([10.110.17.14]) with mapi; Fri, 24 Jun 2011 00:33:17 -0400 To: Jan Schneider , "internals@lists.php.net" Date: Fri, 24 Jun 2011 00:34:08 -0400 Thread-Topic: [PHP-DEV] foreach() for strings Thread-Index: AcwxjGtzmPWthTqlSkeOP9Uynr52EwAlhT0Q Message-ID: References: <4E02D95F.7030303@garfieldtech.com> <20110623114012.Horde.RFhDBxPcj3hOAwn8LIYjSMA@neo.wg.de> In-Reply-To: <20110623114012.Horde.RFhDBxPcj3hOAwn8LIYjSMA@neo.wg.de> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: acceptlanguage: en-US Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Subject: RE: [PHP-DEV] foreach() for strings From: johncrenshaw@priacta.com (John Crenshaw) > -----Original Message----- > From: Jan Schneider [mailto:jan@horde.org]=20 > > And if that very same string that's supposed to be an array is =20 > processed using the $var[$n] syntax nowadays is any different? It's =20 > not, you won't get an error message for that either, and it's the same =20 > amount of work to track this down. Granted, making PHP behaving the =20 > same in foreach gives you one more place to track down such errors, =20 > but making it easier to track down developer errors is not anything =20 > that should keep PHP from adding new features. > > Jan. In theory, yes, but in practice this doesn't seem to happen with any freque= ncy (actually, I'm having a hard time thinking of a time when this has EVER= happened to me.) On the other hand, warnings about foreach getting somethi= ng that wasn't iteratable are commonplace for me, and more often than not, = it is a string. I think it's perfectly appropriate for any language to avoid "high risk" fe= atures (features that are likely to result in buggy code, or features that = are likely to result in bugs evading detection.) My code has enough bugs al= ready, so any language feature that finds my bugs for me is more than welco= me. Consider implicit vs. explicit returns. If a function always returns the va= lue of the last statement (implicit) this is likely to result in unpredicta= ble behavior and hidden bugs, when a warning could have been issued instead= . Typing "return" clarifies intent and is a very small price to pay to avoi= d those errors. In this case, typing "new TextIterator()" in the handful of= cases where you actually needed to iterate a string is a VERY small price = to pay for: 1. The ability to get meaningful warnings when you didn't intend to iterate= the string (by far the more likely scenario) 2. The ability to easily fix your code when you decide that a universal cha= racter set really is valuable 3. The ability to clearly see the intent of the code John Crenshaw Priacta, Inc.