# Required parameter after optional one

- Thread: https://externals.io/message/114007
- Original archive: https://news-web.php.net/php.internals/114007
- Started by Benjamin Morel on 2021-04-09T07:23:26+00:00
- Messages: 2
- RFC: Deprecate implicitly nullable parameter types (Accepted) — https://externals.io/rfc/deprecate-implicitly-nullable-types.md
- RFC: Named Arguments (Implemented (PHP 8.0)) — https://externals.io/rfc/named_params.md
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · RFCs at https://externals.io/rfc.md · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #114007 — Benjamin Morel — 2021-04-09T07:23:26+00:00

URL: https://externals.io/message/114007#114007

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

---

## #114026 — Nikita Popov — 2021-04-12T09:47:55+00:00

URL: https://externals.io/message/114007#114026 · In reply to: #114007

On Fri, Apr 9, 2021 at 9:24 AM Benjamin Morel <benjamin.morel@gmail.com>
wrote:

> 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);
> ```
>
> > […]
> /in/DmhYG on line 3
> > […]
>
> 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?
>

I'd say it's the other way around, and named parameters are at fault here:
We should not be allowing that call. We should probably explicitly drop
such default values during compilation (which will change reflection output
though).

Nikita
