Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111823 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 13477 invoked from network); 3 Sep 2020 16:06:27 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Sep 2020 16:06:27 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 8523A180538 for ; Thu, 3 Sep 2020 08:11:38 -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,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-il1-f178.google.com (mail-il1-f178.google.com [209.85.166.178]) (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 08:11:38 -0700 (PDT) Received: by mail-il1-f178.google.com with SMTP id m1so2809117ilj.10 for ; Thu, 03 Sep 2020 08:11:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=datadoghq.com; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iDTpXa3Thei8XD6xvgaU9BqiZszsZ/lbEDctsdhKQMg=; b=DrEZk/yhEfC2fNQ0lHJU0duZ44NmU8zYT8OhT4hLqvMgggdQ+e/StPBzxm1Z1daXax Q48CFUQ/gOM+NEAk6WeNZE5dg79djCIqCCLSwC+8v/sedpegUbbmjuu4w7a3mUF9Bc/X eSpxDYVlCnEd69fv36RxtcALsmLlUhOgTeuJs= 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=iDTpXa3Thei8XD6xvgaU9BqiZszsZ/lbEDctsdhKQMg=; b=n/1uyGqXkcLp2UgdfjVt90XPzXU4VetQU/wY4eY3QB/glw4YZNf6qtM4e8sdgE/zQo dFm6Tf3/ZTOmq2Zb0ZnvJAxYUGiR9g/s3HCUDgRa4fro0L/QcrPaHqUuKo8Eg+k+5bUL yWT55IZZyJREQ9KdzTqgD1EMQCUCdyWmTxhyAFTigyLTUzlzRBNICSyZVyJy4VxP6EFL z/x8wtBkn09w0C96H2Tj0D1LHqlMOxjUwffC4hjUPNR1jkQJRoxwkahVHT8dODpMoGrN u1bnDQ/poENdgc91CE+jAWt1NsnikTr1mYT0NFtLR5UYSEsinlKkc0eia39lGWljRm4n I5GQ== X-Gm-Message-State: AOAM530t2DCEuZMKPkJSIi70KmkaCc0Sv7fpW2mz09FyzJ7OfrELKlaI LDAo3bdfg56NOY5b2osDk4YZrg1dPz5ZgcqcXBw8RA== X-Google-Smtp-Source: ABdhPJztWmHcY4/FZhwa1zFzI4BmsFkiGKckTzDUSOMv0hrqesulOP9pbheCKC5f4t2leEQMk1NX0AlyrrXIxo20Ow0= X-Received: by 2002:a05:6e02:12ae:: with SMTP id f14mr3765298ilr.232.1599145897480; Thu, 03 Sep 2020 08:11:37 -0700 (PDT) MIME-Version: 1.0 References: <89FF9360-609A-439F-BDBE-B3B4C141E00F@newclarity.net> <20200903095840.4b83640d@mcmic-probook.opensides.be> In-Reply-To: Reply-To: Levi Morrison Date: Thu, 3 Sep 2020 09:11:26 -0600 Message-ID: To: Sara Golemon Cc: Markus Fischer , PHP internals Content-Type: text/plain; charset="UTF-8" Subject: Re: [PHP-DEV] Draft RFC: foreach iteration of keys without values From: internals@lists.php.net ("Levi Morrison via internals") On Thu, Sep 3, 2020 at 8:32 AM Sara Golemon wrote: > > 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 Question for those who know about opcache optimizations: is it feasible to avoid fetching the current value if the value is otherwise unused and the variable-variable features are not used either?