Re: Draft RFC: foreach iteration of keys without values

From: Date: Wed, 02 Sep 2020 20:58:07 +0000
Subject: Re: Draft RFC: foreach iteration of keys without values
References: 1 2 3 4  Groups: php.internals 
Request: Send a blank email to internals+get-111797@lists.php.net to get a copy of this message
On Wed, 2 Sep 2020, 21:54 Dik Takken, <dik.takken@gmail.com> wrote: > On 02-09-2020 21:31, Dik Takken wrote: > > 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. > > Replying to myself: It just occurred to me that array destructuring > already allows omitting values: > > [, , $username] = getUserData(); > > I still do find using void here more clear though, more intentional. > Yes, the current syntax lacks explicit intent and looks like a syntax error. Anything would be better than this, I think. :) > > 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) {} > > > > Given the array destructuring syntax, an alternative syntax might be: > > function foo($arg,) > > Again, I would prefer to see void here in stead of a trailing comma. In > function calls a trailing comma is already allowed and it has a > completely different meaning, which can be confusing. > > Regards, > Dik Takken > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: https://www.php.net/unsub.php > >

« previous php.internals (#111797) next »