Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111804 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40645 invoked from network); 3 Sep 2020 08:53:39 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 08:53:39 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id DEC811804D8 for ; Thu, 3 Sep 2020 00:58:44 -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=-0.5 required=5.0 tests=BAYES_05,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from smtp-in.fusiondirectory.org (smtp-in.opensides.be [195.154.20.156]) (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 ; Thu, 3 Sep 2020 00:58:44 -0700 (PDT) Received: from smtp-in.fusiondirectory.org (localhost.localdomain [127.0.0.1]) by smtp-in.fusiondirectory.org (Proxmox) with ESMTP id EAB35101281 for ; Thu, 3 Sep 2020 09:58:41 +0200 (CEST) Received: from smtp.fusiondirectory.org (smtp.geekview.be [195.154.20.141]) by smtp-in.fusiondirectory.org (Proxmox) with ESMTP id B8EB1101067 for ; Thu, 3 Sep 2020 09:58:41 +0200 (CEST) Received: from mcmic-probook.opensides.be (63.120.199.77.rev.sfr.net [77.199.120.63]) by smtp.fusiondirectory.org (Postfix) with ESMTPSA id 802688AB10 for ; Thu, 3 Sep 2020 09:58:41 +0200 (CEST) Date: Thu, 3 Sep 2020 09:58:40 +0200 To: internals@lists.php.net Message-ID: <20200903095840.4b83640d@mcmic-probook.opensides.be> In-Reply-To: References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> Organization: FusionDirectory X-Mailer: Claws Mail 3.14.1 (GTK+ 2.24.31; x86_64-pc-linux-gnu) MIME-Version: 1.0 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: come.chilliet@fusiondirectory.org (=?UTF-8?B?Q8O0bWU=?= Chilliet) Le Wed, 2 Sep 2020 19:13:20 +0200, Nikita Popov a =C3=A9crit : > Just like the first time this was discussed, I don't think this RFC makes= a > sufficient case on why we need explicit syntax for this. Just ignoring the > value is an existing pattern that works across all PHP versions: >=20 > foreach ($iterable as $key =3D> $_) { ... } I currently use foreach (array_keys($array) as $key) { ... } to avoid complains from code analysers on unused var, is it slower? One obvious pro of having a dedicated syntax is not having to ask those questions to ourselves while coding. > Iterating over just the keys is not a super common pattern and we already > have a reasonable way to do it (that is imho just as clear, and actually > more concise than the proposed "null" variant). The only potential > advantage to a dedicated syntax that I see is that there could be iterato= rs > that can cheaply produce keys, but have expensive to produce values. That > seems like an edge case of an edge case though, and is a situation where > manually calling ->key() would be justifiable. In our code base I thinks it is quite common. grepping on "foreach (array_keys" gives me 51 cases, while grepping "foreac= h (" gives me 1153, so that=E2=80=99s 4% of our foreach uses. C=C3=B4me