Re: Draft RFC: foreach iteration of keys without values

From: Date: Wed, 02 Sep 2020 11:27:11 +0000
Subject: Re: Draft RFC: foreach iteration of keys without values
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-111777@lists.php.net to get a copy of this message
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

« previous php.internals (#111777) next »