Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:80872 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 12996 invoked from network); 20 Jan 2015 13:41:50 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 20 Jan 2015 13:41:50 -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:48735] helo=mail-ig0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E2/90-07480-C1B5EB45 for ; Tue, 20 Jan 2015 08:41:48 -0500 Received: by mail-ig0-f179.google.com with SMTP id l13so16675724iga.0 for ; Tue, 20 Jan 2015 05:41:45 -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=Q0SsYlHbc+HKDVdeRN9/eBwU2AU+znN9Qr4f3UAt0+k=; b=ztpH8f3IOPT/RaYoCKBJ+9IYadCfCcIJSgWReQLP90N09f0Jp3YcHq6aldm188Hg5R YCMEdCruwbFP/4SX/U2709kbQas5+Ep14MEb32M3eLfyeTGzqnbXzou0ACVusjrOy4Mu iwn/XHlDwvJPomAo8LvSCV9gVsi26+OFRAiyQP2EOOW8xQRmhnmrdHxlMSiwcQViGoSp f2mtdYNzpKwmTq5FfOGqZ3si9TfdhHvo7fUXPgv5MWX6ZAeEQKHj1rGLjLUGojsgMrbE BLUeeL02WEC2EgDNvYwTGQZZo/jnfwWX4JNyZBGJPQ0UBTSArGGLbXtIvW9XSmE4U2Il iLZw== MIME-Version: 1.0 X-Received: by 10.42.203.141 with SMTP id fi13mr33713568icb.52.1421761305789; Tue, 20 Jan 2015 05:41:45 -0800 (PST) Received: by 10.50.248.45 with HTTP; Tue, 20 Jan 2015 05:41:45 -0800 (PST) In-Reply-To: References: Date: Tue, 20 Jan 2015 07:41:45 -0600 Message-ID: To: Pierre Joye Cc: Andrea Faulds , Niklas Keller , PHP Internals Content-Type: multipart/alternative; boundary=20cf3040ebf4964aaf050d1599ce Subject: Re: [PHP-DEV] in Operator From: pencap@gmail.com (Mike Willbanks) --20cf3040ebf4964aaf050d1599ce Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable 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. 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 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 fore= ach 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 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 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 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 --20cf3040ebf4964aaf050d1599ce--