Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111813 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87389 invoked from network); 3 Sep 2020 13:09:29 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 13:09:29 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 1B4061804D9 for ; Thu, 3 Sep 2020 05:14:33 -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=-1.9 required=5.0 tests=BAYES_00,FROM_EXCESS_BASE64, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,UNPARSEABLE_RELAY autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from smtpbgeu1.qq.com (smtpbgeu1.qq.com [52.59.177.22]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 3 Sep 2020 05:14:31 -0700 (PDT) X-QQ-mid:Yeas13t1599135261t868t23784 Received: from 4B562073492C4058817F84E016DE3445 (me@jhdxr.com [116.14.113.108]) X-QQ-SSF:00100000000000F0FG1000000000000 To: "'Dik Takken'" , "'Nikita Popov'" , "'Mike Schinkel'" Cc: "'John Bafford'" , "'PHP internals'" References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> In-Reply-To: Date: Thu, 3 Sep 2020 20:14:19 +0800 Message-ID: <006901d681eb$c0cd5c70$42681550$@jhdxr.com> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Mailer: Microsoft Outlook 16.0 Thread-Index: AQIj5psuMpB5wKKV5K/mY4bl8xogJwGTgrRzAR2W11yopn/QUA== Content-Language: zh-cn X-QQ-SENDSIZE: 520 Feedback-ID: Yeas:jhdxr.com:qybgforeign:qybgforeign6 X-QQ-Bgrelay: 1 Subject: RE: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: me@jhdxr.com (=?utf-8?b?Q0hVIFpoYW93ZWk=?=) Regarding the unused variable, I think OPCache should be able to = identify and eliminate it. I don't think it's necessary to add a new = syntax here. Array destructuring sounds like a similar case to me. If you don't like = [, , $v] =3D$arr, you can use [$_, $_, $v]=3D$arr instead. Regards, CHU Zhaowei -----Original Message----- From: Dik Takken =20 Sent: Thursday, September 3, 2020 3:31 AM To: Nikita Popov ; Mike Schinkel = Cc: John Bafford ; PHP internals = Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without = values On 02-09-2020 19:13, Nikita Popov wrote: > Just like the first time this was discussed, I don't think this RFC=20 > makes a sufficient case on why we need explicit syntax for this. Just=20 > ignoring the value is an existing pattern that works across all PHP = versions: >=20 > foreach ($iterable as $key =3D> $_) { ... } While this works fine, it does introduce an unused variable. Code = inspection currently complains about that, and for good reason, which is = annoying. Even if we decide that it is not worth the trouble for foreach loops, = there are other cases where this new syntax can work well. Array = destructuring has already been mentioned. Another case is the one where a function intentionally does not use one = of the arguments passed to it. This happens easily when using callbacks = or when implementing interfaces. A function declaration could look like this: function foo($arg, void) {} This indicates that the second parameter is intentionally left unused. Perhaps it is a good idea to generalize the RFC to the general concept = of "using void to intentionally ignore a variable". Maybe pick just one = use case for actual implementation and extend later using followup RFCs. Regards, Dik Takken -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, = visit: https://www.php.net/unsub.php =20