Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111835 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 53464 invoked from network); 3 Sep 2020 21:03:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 21:03:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id AD71318054D for ; Thu, 3 Sep 2020 13:08: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,HTML_MESSAGE, 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-ua1-f42.google.com (mail-ua1-f42.google.com [209.85.222.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 ; Thu, 3 Sep 2020 13:08:28 -0700 (PDT) Received: by mail-ua1-f42.google.com with SMTP id u48so1319586uau.0 for ; Thu, 03 Sep 2020 13:08:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=pD4zvVfAgJqKdL04oH0Sx4VyzheflJgEERCVly7lFkE=; b=gOrrhXS/O+zBQxT4JuvhyZVeDDL/MefkbBb3UTZzHPFUJhrsT6y0gqPGQJU3mTvM5x m4ORMcgCMPWnaRnW0mQfL/OxEPeXFEZxImJ2Xg6ojSmkG8JIxtW/B165yJNF+TZidcZl bXNk7wLyUgPMQiEap+eJlxZxHFN6aXUjyH7YK7QFA48ZVh/ehEdVeWNJRd2Yjptm6YHP J/wJ9NKRuq+GbUKD9X0GgjWaqZnLhILYr9TQ140Py83+JQg9RgleBn97AmID6yhYCFaq F9LYJ74KiUoIlzt3SU7uZl+6vX+/iELva8/hjJuo6jIabyE7dyNwApFa6dADBIjafzA+ 9E4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=pD4zvVfAgJqKdL04oH0Sx4VyzheflJgEERCVly7lFkE=; b=l4LkJbOpoiZG7Y48ZQJ7kMql/xHlEOA0GnuA46jqABwjFAnhwIJsTfPNHDwtfHArpj YqBJCCiXf60MS7Q7PI73cOyB1udGIGPPLbWD2LIopo1ueYfgF4aGQa9uW1Gk7n45G2ww pi7hrNXeOfKAw0YgvWE2CPF/Piom2sqLiQlP4L53ivLxDdZ2bDOyNiux4Vn8XdJVQbd4 MoP9QcFtByG5LdCeNrd1Ltzo+z5AhX23KrvG246wWH3ta3DFoYmg9xND8mC2wFO8oH+f ACaT+sMm/lMKIAWhjuytIzj4kQdiw4CcLXTGMzj6yYTwL9XEsLK3XrnTG8oMN89NHM73 gLqw== X-Gm-Message-State: AOAM530TEQ5XiIrk20AF58CooMj+ftRkeaGromg+uWRHLqDzJozJAW5O dxIzOdVfmFbkCaexS0aGmowegsOchjkMxeeNczM= X-Google-Smtp-Source: ABdhPJzDN+oeUpi7ZloG/NZdWipAdCQp+DQZXMe4pybgGVrcuBPArP2nSBHGqIv3/w6gfNAiZ8b2GY6AqVzbpkUSaWE= X-Received: by 2002:ab0:1696:: with SMTP id e22mr2718009uaf.1.1599163705812; Thu, 03 Sep 2020 13:08:25 -0700 (PDT) MIME-Version: 1.0 References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> <20200903095840.4b83640d@mcmic-probook.opensides.be> In-Reply-To: Date: Thu, 3 Sep 2020 16:08:13 -0400 Message-ID: To: Sara Golemon Cc: David Rodrigues , PHP internals Content-Type: multipart/alternative; boundary="0000000000009f6a6f05ae6e50a3" Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: chasepeeler@gmail.com (Chase Peeler) --0000000000009f6a6f05ae6e50a3 Content-Type: text/plain; charset="UTF-8" On Thu, Sep 3, 2020 at 12:05 PM Sara Golemon wrote: > On Thu, Sep 3, 2020 at 10:35 AM David Rodrigues > wrote: > > > Do you think that it could be proxied? I mean, optimize foreach > > (array_keys()...) syntax to not call array_keys() in fact, but a > optimized > > version of foreach to handle key only. I don't know it opcache could do > > that, and if it already does. > > > > > I wouldn't use the word "proxied", but yes. In my mind the compiler would > see: > > foreach(\array_keys($arr) as $key) { > > and quietly transform that into: > > foreach ($arr as $key => $_unusedVariableNameThatIsntEvenSpilledToTheScope) > { > > Are there other instances where we have optimizations like this? If so, are they documented? In terms of readability, I'm more likely to do $keys = array_keys($array); foreach($keys as $key){ That would obviously break the optimization we're talking about though. Which makes me wonder if there are other places like that. > Thus not iterating the array twice and creating a temporary array of key > names. > > -Sara > -- Chase Peeler chasepeeler@gmail.com --0000000000009f6a6f05ae6e50a3--