Required parameter after optional one
| From: | Benjamin Morel | Date: | Fri, 09 Apr 2021 07:23:26 +0000 |
| Subject: | Required parameter after optional one | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-114007@lists.php.net to get a copy of this message | ||
Hi internals,
I'm wondering why PHP 8 started warning about required parameters declared
after optional ones, when this version is the one that also introduced
named parameters, which can take advantage of this:
```
function test($a = 1, $b) {
echo $a, $b;
}
test(b: 2);
```
> Deprecated: Required parameter $b follows optional parameter $a in
/in/DmhYG on line 3
> 12
https://3v4l.org/DmhYG
If I'm not mistaken, the introduction of this warning (January 2020
<https://externals.io/message/108052>)
predates the introduction of named
parameters (May 2020 <https://wiki.php.net/rfc/named_params>), which
could
explain why it would have temporarily made sense to introduce this warning.
Shouldn't it be removed now, that it makes IMO full sense with named
parameters to have required and optional parameters at arbitrary positions?
Thank you for your time,
— Benjamin