>Четверг, 9 декабря 2021, 8:22 +03:00 от André Hänsel <an...@webkr.de>: > >PHP 8 has named parameters in function calls, Kotlin has named parameters in >function calls. > >Kotlin has this handy feature that you can put parameters with defaults >before normal ones. Those parameters can then only be used by naming them. >See also: https://kotlinlang.org/docs/functions.html#default-arguments > >This is very useful because I can add an optional parameter to a function >and prevent users of my function from using the parameter in a positional >way. This way I don't have to make a compatibility promise to never change >the position of this parameter. > >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 > >-- >PHP Internals - PHP Runtime Development Mailing List >To unsubscribe, visit: https://www.php.net/unsub.php 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