Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80874 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 16204 invoked from network); 20 Jan 2015 13:48:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 13:48:15 -0000 Authentication-Results: pb1.pair.com header.from=marcio.web2@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=marcio.web2@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.217.177 as permitted sender) X-PHP-List-Original-Sender: marcio.web2@gmail.com X-Host-Fingerprint: 209.85.217.177 mail-lb0-f177.google.com Received: from [209.85.217.177] ([209.85.217.177:49627] helo=mail-lb0-f177.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id ED/31-07480-E9C5EB45 for ; Tue, 20 Jan 2015 08:48:15 -0500 Received: by mail-lb0-f177.google.com with SMTP id p9so10238062lbv.8 for ; Tue, 20 Jan 2015 05:48:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding; bh=6jsUzyhDxaa+O2lki2f5hrBl6VxXUzLc6164BBTB8Es=; b=LBEgWVJf8ZDwYIGtQu1B42aP9BzBbY00WBrA79wqdwXu5G/17QDCXxM2DQ74DLMN/j aA+hO2nYaF2hr6gngC/XokEbomJm66VxtwtC8jDWAH2QzcQoOoLH8iYQFWJOXlDfQj+J /e5T/if1qb/WRD5BSbbUqHdIzRe5oJnjO8y30ec5He/5yRjcdFuyTxZFTwSWtj/hoK71 uWtSOFdleGagdcg/5H3lMarV2TN1aay5Q8GDnyyR9hh8mEVCpy6fOMqMBur50q6O8UAZ zT1uOOjpAy+1A1yWsM1IN9bneEz5z1XDOUUiUAii29wWcWre2stG98Aj3S93IoStkt/Y jcEQ== X-Received: by 10.152.115.230 with SMTP id jr6mr38548994lab.2.1421761691711; Tue, 20 Jan 2015 05:48:11 -0800 (PST) MIME-Version: 1.0 Received: by 10.152.21.101 with HTTP; Tue, 20 Jan 2015 05:47:51 -0800 (PST) Reply-To: marcio3w@gmail.com In-Reply-To: References: Date: Tue, 20 Jan 2015 10:47:51 -0300 Message-ID: To: Mike Willbanks Cc: Pierre Joye , Andrea Faulds , Niklas Keller , PHP Internals Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] in Operator From: marcio.web2@gmail.com (Marcio Almada) Hi, Mike, the use of "in" as `for ($var in $object) {};` could be the subject for another distinct RFC since it's doing something different from the original proposal: var_dump("PHP" in ["PHP", "C", "Java"]); // true 2015-01-20 10:41 GMT-03:00 Mike Willbanks : > Hello Pierre, Andrea and Niklas, > > On Mon, Jan 19, 2015 at 11:35 PM, Pierre Joye wrot= e: > >> On Tue, Jan 20, 2015 at 6:15 AM, Andrea Faulds wrote: >> >> On 20 Jan 2015, at 03:30, Mike Willbanks wrote: >> >> >> >> I am very familiar with the in operator. However, the implementatio= n >> >> would be incomplete without handling loops via the in operator. Many >> >> people when seeing an in operator also think of JavaScript. In that >> case >> >> the in operator iterates over properties. As such in PHP we should b= e >> able >> >> to iterate over associative arrays should the syntax be added. >> >> >> https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statem= ents/for...in >> > >> > Why? We already have foreach/as which does exactly that, and unlike JS >> which added for/of, there=E2=80=99s nothing wrong with PHP=E2=80=99s for= each so we don=E2=80=99t >> need support for a new symbol. >> >> Indeed, exactly same feature. > > > It certainly is the same feature from the foreach perspective. I'm not > against leaving it out, however, it would be much like the in operator th= us > providing some additional syntax sugar. Many people that often program i= n > JavaScript are used to having: > array.forEach(function()), for (property in object), etc. > > From my perspective it would seem like a hole in the implementation for i= t > to be missing but that is also due to having such a split of time between > the two languages. Take for instance python utilizing the same thing: > > for variable in expression: > ... code > ... > > as well as ruby: > > for variable [, variable ...] in expression [do] > code > end > > Ultimately, I would feel that having the in operator would also create th= e > expectation that in PHP we would be able to achieve the following: > > for ($var in $array) {} and/or for ($var in $object) {}; > > Certainly foreach is more rich but I believe based on other languages and > paradigms that this would be something people would request and expect if > the in operator was to make it into PHP 7. > > Regards, > > Mike