Le Wed, 2 Sep 2020 19:13:20 +0200, Nikita Popov <nikita....@gmail.com> a écrit : > 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 => $_) { ... }
I currently use foreach (array_keys($array) as $key) { ... } to avoid complains from code analysers on unused var, is it slower? One obvious pro of having a dedicated syntax is not having to ask those questions to ourselves while coding. > Iterating over just the keys is not a super common pattern and we already > have a reasonable way to do it (that is imho just as clear, and actually > more concise than the proposed "null" variant). The only potential > advantage to a dedicated syntax that I see is that there could be iterators > that can cheaply produce keys, but have expensive to produce values. That > seems like an edge case of an edge case though, and is a situation where > manually calling ->key() would be justifiable. In our code base I thinks it is quite common. grepping on "foreach (array_keys" gives me 51 cases, while grepping "foreach (" gives me 1153, so that’s 4% of our foreach uses. Côme -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: https://www.php.net/unsub.php