Re: Allow default parameters before non-default ones?
| From: | Christoph M. Becker | Date: | Thu, 09 Dec 2021 12:45:51 +0000 |
| Subject: | Re: Allow default parameters before non-default ones? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116601@lists.php.net to get a copy of this message | ||
On 09.12.2021 at 13:03, Rowan Tommins wrote:
> On 09/12/2021 05:22, André Hänsel wrote:
>
>> If I try the same thing in PHP 8.0 I get a Deprecated warning and if I
>> try
>> it in PHP 8.1 I get something that I don't understand:
>> https://3v4l.org/cg4DA
>
> There are two diagnostics showing in 8.1, the deprecation on the
> declaration, and a fatal error on the call.
>
> What's happened is that given your signature:
>
>> function blah($foo = "deffoo", $bar) { ... }
>
> PHP has decided it doesn't make sense, and re-interpreted it as this:
>
>> function blah($foo, $bar) { ... }
>
> Then when you try to call it:
>
>> blah(bar: "1");
>
> You're missing the now-mandatory parameter $foo, so you get a fatal error.
>
>
> I'm not sure exactly why this behaviour has changed, and can't see any
> mention in the Release or Migration pages in the manual. It's not a
> *huge* break, because named params have only existed since 8.0, but it
> is technically a breaking change in a minor version.
>
> The only relevant discussion I've found is this, where Nikita is I think
> hinting at the new behaviour:
> https://externals.io/message/114007#114026
The new behavior has been introduced[1] quite a while after this mail
had been sent. I agree with the idea outlined in the commit message.
I suggest to document that in the migration guide, and in the manual proper.
[1]
<https://github.com/php/php-src/commit/afc4d67c8b4e02a985a4cd27b8e79b343eb3c0ad>
--
Christoph M. Becker