Re: Allow default parameters before non-default ones?

From: Date: Mon, 13 Dec 2021 23:12:00 +0000
Subject: Re: Allow default parameters before non-default ones?
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-116642@lists.php.net to get a copy of this message
  >Четверг, 9 декабря 2021, 8:22 +03:00 от André Hänsel <andre@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: ¼ >Œq6Uµ›§ĘVhÔ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  

« previous php.internals (#116642) next »