Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111776 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15054 invoked from network); 2 Sep 2020 11:43:17 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2020 11:43:17 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1231D1804E3 for ; Wed, 2 Sep 2020 03:48:10 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ej1-f47.google.com (mail-ej1-f47.google.com [209.85.218.47]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Wed, 2 Sep 2020 03:48:09 -0700 (PDT) Received: by mail-ej1-f47.google.com with SMTP id i26so5912907ejb.12 for ; Wed, 02 Sep 2020 03:48:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=95CNzHdh4d+JeWoKQB+TKB02zkbxCqQGKGjj1DuVopk=; b=RF13OpDcQjEfMXgEFASQjkrmkpSOAGEucILU0guI3hqKetKUeFt39UKcM1AgZdm3uS sxZJsYBkrl3hrJSH/Aq2LHTH5ewb1SSTRdynDfyJ79tJGIOcRhuw2fSVTKsX6OP8T5W7 R0xo6KDCNQ50h6+STkqqGNG6H1/2UrNETsDGZh2plT6+ZznM7YMZxYHZyKxUXr8rDv3F DfbOq1EVj7hjPlvnQqwcojQyyTHSYRKHSqE6w1YYeSb0AjNjJ9sr/WEi5Qz/8YJTezd3 JLXE/Qj7Pjcf3qrUPmRgi/IyKBTq5LhoqMZMz5bm+mtNdjZAcohZh/BcVp/US9JHB+0F dybA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=95CNzHdh4d+JeWoKQB+TKB02zkbxCqQGKGjj1DuVopk=; b=WHA7YDCpL5HvWJoz/EVYJqfuSOG4iaHc3Bp9VcIxDqwm0LcURGhaobsyLKiFBIZ71v /AmIJXkQgdiu3VlXASQUKXkq76vcvJqFuNpDp87ZJxwann4lKUhuE/9mDwnYWNzW5AAr EQTKT8nbe8o4V4ExSR2LstE/bh+mu69s9GU8C3NIjimAQKsU9BRQ/wH+ZdL2k47WktWE Pbv5xe6vLE4l1Di+Cta+UTCK9mio88KCc1yuxO9YQqPcgqVQyI+P5iInvW3sI7X9hQCt hYfHQDNRj2CC9HK6gWozWurAgnuzZgkkDkrMyPujyLbpWGOzu7VkprlPUDR7Fn/7XXbK Xnyw== X-Gm-Message-State: AOAM533CMa1RmbqYwi0/EGZ36iSo2LMlcFj8HzVbQ9cONiMYvZpnDhk3 FMpqEwpJefjOlg1gcDg7G6Fwngl8eUmOVhzJ/q2W6R7V X-Google-Smtp-Source: ABdhPJyIraM8DKpY8BDdkGV/hePQrqHzHIFO3EZVtMniLszbJDIfmZaayGJtdeCd7uXyLnAQLUBCLgtScYgIa7BfIf4= X-Received: by 2002:a17:906:914b:: with SMTP id y11mr5956605ejw.145.1599043686093; Wed, 02 Sep 2020 03:48:06 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a54:3ac6:0:0:0:0:0 with HTTP; Wed, 2 Sep 2020 03:48:05 -0700 (PDT) In-Reply-To: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> Date: Wed, 2 Sep 2020 10:48:05 +0000 Message-ID: To: Mike Schinkel Cc: John Bafford , PHP internals Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: olleharstedt@gmail.com (=?UTF-8?Q?Olle_H=C3=A4rstedt?=) An alternative syntax would be foreach($iterable as $key =3D> _) { ... } Using underscore as a way to signal "I don't care about this value". Same could be possible with list destructoring, like [_, _, $something] =3D foo(); This syntax comes from OCaml. Possibly other languages, too? Not sure. 2020-09-02 3:15 GMT, Mike Schinkel : > This is a new thread for John Bafford's RFC which he mentioned on another > thread, see below: > > https://wiki.php.net/rfc/foreach_void > > >> On Aug 31, 2020, at 5:50 PM, John Bafford wrote: >> >> Hi Riikka, >> >>> On Aug 31, 2020, at 14:13, Riikka Kalliom=C3=A4ki >>> wrote: >>> >>> A common pattern that I've seen that could dearly use PHP internal >>> optimization, if possible, would be: >>> >>> foreach (array_keys($array) as $key) { >>> } >> >> I have a draft RFC (https://wiki.php.net/rfc/foreach_void) and patch >> (https://github.com/jbafford/php-src/tree/foreachvoid against php 7.0, I >> think) that helps with this, by allowing the following syntax: >> >> foreach($iterable as $key =3D> void) { ... } >> >> This would iterate over the keys of the iterable, and does not retrieve >> the values at all. >> >> In theory, this should be a general performance win any time one needs t= o >> iterate over only the keys of an iterable, because it does not require t= he >> use of an O(n) iteration and building of the array that array_keys() >> would, plus it works on non-array types (such as generators or iterators= ). >> It also is more performant than foreach($iterable as $key =3D> $_) {}, >> because it omits the opcode that instructs the engine to retrieve the >> value. (Presumably, a future direction could include using this request = to >> inform generators or iterators to only return keys, and not values, whic= h >> could further improve performance, especially if value generation is >> expensive. But that is out of scope for this RFC.) >> >> If this is something we'd like for PHP 8.1 and there are no major >> objections to the idea, then after 8.0 is released, I can move the RFC o= ut >> of Draft and into Under Discussion, and presuming a vote passes, I'll >> update the patch as necessary to work against 8.0. But my time is limite= d >> and I'm not willing to put further time into the code unless an RFC vote >> passes. >> >> Thoughts anyone? > > +1 from me. > > BTW, your RFC says "Next PHP 7.x" for Proposed Version; might need to upd= ate > that? > > -Mike