Re: Allow default parameters before non-default ones?
| From: | Larry Garfield | Date: | Tue, 14 Dec 2021 18:34:17 +0000 |
| Subject: | Re: Allow default parameters before non-default ones? | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-116644@lists.php.net to get a copy of this message | ||
On Mon, Dec 13, 2021, at 5:12 PM, Kirill Nesmeyanov wrote:
> I'll add that leading optional parameters are needed to implement
> currying and partial application.
>
> ```
> function foo(int $opt = 42, int $req) {}
>
> $foo = curry(foo(...), 23);
>
> // $foo = fn($opt = 42, $req = 23);
> ```
>
> While this is not a popular practice in PHP, this deprecation
> notification «breaks» all code that uses functional pradigm/concepts.
>
> --
> Kirill Nesmeyanov
This is simply untrue, and I have not seen any code that does currying in that fashion. If
anything, trailing optional arguments are what make currying difficult as it's unclear when to
"stop" and invoke the underlying function. (The previous PFA RFC had that solved.)
I do not like the original proposal here either, though. If we decide we want to allow an argument
to require that it be called named, that should have an explicit keyword to indicate such. It
should not be an implicit trick of otherwise confusing argument ordering.
--Larry Garfield