On Thu, Jun 17, 2021, at 2:54 AM, Côme Chilliet wrote:
> Le Wed, 16 Jun 2021 11:16:28 -0500,
> "Larry Garfield" <la...@garfieldtech.com> a écrit :
> 
> > Hi folks.  The vote for the Partial Function Application RFC is now open, 
> > and
> > will run until 30 June.
> > 
> > https://wiki.php.net/rfc/partial_function_application
> 
> I do not understand how this ... placeholder works, it feels inconsistent.
> 
> From the examples:
> 
> > $c = stuff(...);
> > $c = fn(int $i, string $s, float $f, Point $p, int $m = 0)
> >   => stuff($i, $s, $f, $p, $m);
> 
> > $c = stuff(1, 'hi', 3.4, $point, 5, ...);
> > $c = fn(...$args) => stuff(1, 'hi', 3.4, $point, 5, ...$args);
> 
> Why is there an additional variadic parameter in this one?

... means "zero or more".  In this case, it means zero, that is, it creates a 
closure that requires no arguments and will call the original function with all 
of the provided values later.  This is the "deferred function" use case 
mentioned further down.

> Also, in the second set of examples:
> > function things(int $i, float $f, Point ...$points) { ... }
>  
> > // Ex 13
> > $c = things(...);
> > $c = fn(int $i, float $f, ...$args) => things(...[$i, $f, ...$args]);
>  
> > // Ex 14
> > $c = things(1, 3.14, ...);
> > $c = fn(...$args) => things(...[1, 3.14, ...$args]);
> 
> What happens to the typing of the variadic parameter here? Why is it removed?
> 
> It would feel natural that the ... means "copy the rest of the parameters from
>  signature". Here it seems it sometimes mean that, and sometimes mean "accept 
> an
>  additional variadic parameter and pass it along".

Internally placeholders do mean the former.  A trailing variadic, though, can 
accept extra arguments of potentially not pre-defined types, so it sort of 
straddles the line.  Variadics make things weird. :-)  (Dating from PHP 5.6.)  
In the majority case, though, thinking of them as "copy the rest of the 
arguments" is accurate.

--Larry Garfield

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to