Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111819 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 6662 invoked from network); 3 Sep 2020 15:26:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 15:26:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id C591D18050B for ; Thu, 3 Sep 2020 07:31:40 -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.8 required=5.0 tests=BAYES_05, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_SOFTFAIL autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f170.google.com (mail-lj1-f170.google.com [209.85.208.170]) (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 07:31:40 -0700 (PDT) Received: by mail-lj1-f170.google.com with SMTP id t7so3272695ljo.13 for ; Thu, 03 Sep 2020 07:31:40 -0700 (PDT) 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=nJ/Og2VsR0TynEh/7QdoB3Yss95ZsfTmK4KqC9apsHk=; b=YgvX1xMeWer5MM33cqaX5LEBTUmEl38+zBd+AWZqJ5guz9Gy7u9db1B45IKafKF3JA hRDCrHJdWZTVfYvzHiPLYcEPwazdWKqw6TGz2O3uY0b64rfMBBC+Qu6OyB/bKOALqO1q k28H55Ufxo7EONQEcjgyFniB2D6enc//EwkZeJHTdBuAgL8oom61/Xp68dQ6xMg/UjbT 0E8S0X3Ty+UgpABtHAITevf0/GsavlEuA0Kz476WVLqPsLnCAoWanY6ZBI54MqbTH8h5 IFNTZemES9jmUbv3/pUbALtDP0lyo5UaSQ85TszcTItyceFfUZeaFeJGvep735sRetZ2 N3vg== X-Gm-Message-State: AOAM531GXi42XAMwYJbLgngpb5zEINeA9JK1tCuFHjoSzkliDsBMirVC 1+R3Y7RGvGJE6m9QQFQOX+uOfFMHw1grzMwSO/Z5/A== X-Google-Smtp-Source: ABdhPJwfT1n4uiU3QpNgb1tttK/Cln4VU6IpZDjM+Tfgk4iqtHOeUicmYnLRobhz8E7C47J03i88Txt16/p+Zph4ZbY= X-Received: by 2002:a05:651c:124b:: with SMTP id h11mr1522332ljh.172.1599143498288; Thu, 03 Sep 2020 07:31:38 -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 09:31:27 -0500 Message-ID: To: Markus Fischer Cc: PHP internals Content-Type: multipart/alternative; boundary="0000000000002924bc05ae699c49" Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: pollita@php.net (Sara Golemon) --0000000000002924bc05ae699c49 Content-Type: text/plain; charset="UTF-8" On Thu, Sep 3, 2020 at 4:19 AM Markus Fischer wrote: > > I currently use foreach (array_keys($array) as $key) { ... } > > to avoid complains from code analysers on unused var, is it slower? > > one argument brought forward initially (sorry, can't find the email > right now) is the resource management: array_keys() has to create a copy > [*] which might be an issue depending on the size of data. > > While I like the idea of more explicit syntax to show intent over a mere convention of $_ being an ignorable var, I do need to call out the foreach (array_keys(...) argument as being a poor motivator. IF (and I heavily stress "if" here) this pattern is common among people trying to show explicit intent and IF it represents a noticeable slowdown, then the solution for it is for the engine to optimize around that by transforming it during compile time. That lets us fix all usages instantaneously without user interaction, and more importantly it allows users to focus on their code being readable (and thereby maintainable) according to whatever coding standards they choose to apply. Again, that same argument is why I actually like the proposal overall. Not because it's so much more performant, but because it empowers developers to write code in a way that will be most readable and maintainable to them, should they happen to just not like the $_ unused var pattern (which is a legit thing to dislike). -Sara --0000000000002924bc05ae699c49--