Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80876 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 19842 invoked from network); 20 Jan 2015 14:05:54 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 14:05:54 -0000 Authentication-Results: pb1.pair.com smtp.mail=pencap@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pencap@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.179 as permitted sender) X-PHP-List-Original-Sender: pencap@gmail.com X-Host-Fingerprint: 209.85.213.179 mail-ig0-f179.google.com Received: from [209.85.213.179] ([209.85.213.179:33023] helo=mail-ig0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 59/F1-07480-EB06EB45 for ; Tue, 20 Jan 2015 09:05:52 -0500 Received: by mail-ig0-f179.google.com with SMTP id l13so16774543iga.0 for ; Tue, 20 Jan 2015 06:05:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=h0hzd5sCq5EN8YaLzJSSwcIqP2P/g6QbwmHC+dwZCXQ=; b=YqiGzt1/LjKNyNYLQyGtk5/CT3OUzeoxJjt/7DraDl5l6+DRhOahq0eb51htJIP/0Q qflJIGKPLqlZLyJUUcXZXA8SmCMjCgVPlmTEO24iDw6XnoZKBS8MWrKCrXw5gYSaYeHg HkRPBTsy8HRfOayHedeC49XdVGlA7a6I2i9OMwjRf+EyodH/kBr5Lr25CMUhikPuxr54 SscDadU6KXudPWp8J7Kp2DrEOMWWkYS7UO0UV5s7T9KdMoTeWgdcnVQe+78PKyh7BbNL qymSLGPWFjbwE7PqmAqEQ4RGXqNyqWQoDxD6L/ENQdgnd/t+fjqo5xMZDi66DQ5/RYwS +9JQ== MIME-Version: 1.0 X-Received: by 10.51.17.11 with SMTP id ga11mr26612653igd.0.1421762747256; Tue, 20 Jan 2015 06:05:47 -0800 (PST) Received: by 10.50.248.45 with HTTP; Tue, 20 Jan 2015 06:05:47 -0800 (PST) In-Reply-To: References: Date: Tue, 20 Jan 2015 08:05:47 -0600 Message-ID: To: marcio3w@gmail.com Cc: Pierre Joye , Andrea Faulds , Niklas Keller , PHP Internals Content-Type: multipart/alternative; boundary=001a1135f140815a26050d15efba Subject: Re: [PHP-DEV] in Operator From: pencap@gmail.com (Mike Willbanks) --001a1135f140815a26050d15efba Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hello, On Tue, Jan 20, 2015 at 7:47 AM, Marcio Almada wrote: > 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 > It is indeed different but ever so slightly, a for loop in this case cannot handle a single argument of true and would cause a parse error. Therefore for ("PHP" in ["PHP, "C", "Java"]) could be handled differently. Again, my main point is that due to other languages the in operator itself also correlates to for ($var in $container), I understand having an additional RFC but this is indeed the place for discussion of such things. Also FYI - in the future please try not to top post and instead post under where you are commenting as it makes it more difficult for people coming later to the thread to see the scope of the conversation. Regards, Mike > > 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 > wrote: > > > >> 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 > implementation > >> >> would be incomplete without handling loops via the in operator. Ma= ny > >> >> people when seeing an in operator also think of JavaScript. In tha= t > >> case > >> >> the in operator iterates over properties. As such in PHP we should > be > >> able > >> >> to iterate over associative arrays should the syntax be added. > >> >> > >> > https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Stateme= nts/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 f= oreach 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 > thus > > providing some additional syntax sugar. Many people that often program > in > > 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 > it > > to be missing but that is also due to having such a split of time betwe= en > > 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 > the > > 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 a= nd > > paradigms that this would be something people would request and expect = if > > the in operator was to make it into PHP 7. > > > > Regards, > > > > Mike > --001a1135f140815a26050d15efba--