Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111794 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 78515 invoked from network); 2 Sep 2020 20:26:31 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Sep 2020 20:26:31 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E1A281804D8 for ; Wed, 2 Sep 2020 12:31:28 -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_H3,RCVD_IN_MSPIKE_WL,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-f42.google.com (mail-ej1-f42.google.com [209.85.218.42]) (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 12:31:28 -0700 (PDT) Received: by mail-ej1-f42.google.com with SMTP id z22so317539ejl.7 for ; Wed, 02 Sep 2020 12:31:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=U7sRl2lWM7kKYkch+y2AfqGpAr04ruk8XbmRRpdA6Ws=; b=U4N7T5vCJ8M0YUSbh0cJ+/5ZLWh6969r89pghdZLnFgBaUJFnVR9RbtyEeG1bAod6W S/rS05b5BRWAWVAtNVj1iM3uP4Yu33R7cP/gYQWwGQrgMt4QXdijfRy/Od8qWIbMj/L+ B7UrZbktIPEBSf2p2F1eHZFNb8o6aOXYyDwTvn/rBOplt5yo1VCijZcGbYYkcrHBcfAE y/P0UCv4Up1Vunz5qCVNGQwcJBSPCw07z9r20QuCeUgrWQHns6HL1/v3MC1UcN6E2g/w fjDoP3UT6HbL5a8kmQ9/4C/hFcNbBFo2vrds8+SQMOcd3Y6jYb07OgGM/rwL4HzYQwMn OBsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=U7sRl2lWM7kKYkch+y2AfqGpAr04ruk8XbmRRpdA6Ws=; b=gh0WiVs7e+qDzH8QOU3sSav12WLuZafVpyQemsTxRJG78Q8pk7Bv3OtsMGLofSQGWL mFPMzX9rEl/mP1OYoYbZZV985L65gelu6GOzfhz7y3ithk3PZd/VQWWcz3R9k7Cg2AF8 GiymGZagTh5HuWkHycMpnFnbfBJ7V/B0Zm2//MBcYwqaIfBk0lpsDxQpagO41iZFNpG/ Lb6fsBh+6zxaW+ZM9knQhWY9IWLOCfpGD563HrJEUpND7fQoFlzgQ6+0VRAit8cK/Y3n 3cvRyBdz4jNbw6oJApyaD7N99SvSBxDvR8K2IjGkwt3px8nnmpjOYZbP2m5To43lPCvj bOIA== X-Gm-Message-State: AOAM533MwGDRelOaZ95YAyM/vA1ZtJ8JL8p8eLrTrTKO2shX5C3gzpV/ LDOSgQZNqnDbauv4+w0QhALkfkGHNfN8Og== X-Google-Smtp-Source: ABdhPJxL9RE6EuNoUd49qOBIrfSg4qe3xtncpIR8aXn0tTl1zB70k/1mW0mI5DLpXc/eLObRN/0mEQ== X-Received: by 2002:a17:906:a109:: with SMTP id t9mr1729994ejy.134.1599075085334; Wed, 02 Sep 2020 12:31:25 -0700 (PDT) Received: from ?IPv6:2001:983:6fc5:1:49c7:735:8c90:b4f5? ([2001:983:6fc5:1:49c7:735:8c90:b4f5]) by smtp.gmail.com with ESMTPSA id n26sm464501ejz.89.2020.09.02.12.31.24 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 02 Sep 2020 12:31:24 -0700 (PDT) To: Nikita Popov , Mike Schinkel Cc: John Bafford , PHP internals References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> Message-ID: Date: Wed, 2 Sep 2020 21:31:23 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.12.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: dik.takken@gmail.com (Dik Takken) On 02-09-2020 19:13, Nikita Popov wrote: > 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: > > foreach ($iterable as $key => $_) { ... } 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