On 02-09-2020 12:48, Olle Härstedt wrote:
> An alternative syntax would be
> 
>     foreach($iterable as $key => _) { ... }
> 
> Using underscore as a way to signal "I don't care about this value".
> Same could be possible with list destructoring, like
> 
>     [_, _, $something] = foo();
> 
> This syntax comes from OCaml. Possibly other languages, too? Not sure.

The underscore is also used for this same purpose in both Python and
Javascript. However, it is a normal, valid variable name in those
languages. It is not in PHP.

I think I would prefer '_' over 'void' because of consistency with other
languages. However, we should also consider that:

1. It is currently a valid constant name (BC break)
2. It might be ambiguous in some contexts in which we may want to use it
in the future. We should carefully consider other possible use cases
like array destructuring.

Regards,
Dik Takken

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

Reply via email to