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

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to