Re: Draft RFC: foreach iteration of keys without values

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

« previous php.internals (#111795) next »