On 25/04/2021 20:25, Larry Garfield wrote:
Discuss.

There has been intense discussion in R11 about how the ? token applies to missing or variadic arguments.

The root of the concern is that in the current proposal, ? applies as either a placeholder for a single replacement, or 0-or-more varadic arguments, depending on its position and the number of arguments.

I and several others believe that this feature would be better served by restricting ? to representing a single argument, and using ...? to represent "anything else" including an empty set.


## To illustrate the scope for confusion:

foo(?) looks like it requires one argument, when in reality it could accept none, 1, or a hundred.

foo(1, ?) looks like it also accepts one argument, but it could accept 0, or 100, depending on the function it is wrapping.

foo(?, 1) definitely requires at least one argument, but could accept more depending on what it's wrapping.


## Suggestion

Based on discussions in R11 there seems to be broad agreement that ? should represent a single argument, and ...? should represent everything else (including no arguments).

Thus:

foo(...?) - Partial of foo with all the arguments copied over.

foo(?, 1, ..?) - 1 required, then 1 fixed, 0 or more others are copied over.

foo(1, ...?) - Fix the first parameter and copy over the rest.


This can be seen as a mirror to the ... operator that accepts a variable number of arguments.

function foo($a, ...$b) {  }

Equally it matches the syntax for unpacking into arguments:

$a = foo($a, ...$b);

Passing more arguments than the partial defines would result in an argument count error.

--
Mark Randall

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

Reply via email to