Skip to content

Conversation

@nikic
Copy link
Member

@nikic nikic commented May 18, 2021

Currently, argument unpacking and named arguments cannot be mixed at all. This relaxes the restriction to allow foo(...$args, named: $arg). The variant foo(named: $arg, ...$args) is forbidden, because we can't ensure that positional parameters come before named parameters in that case (without more intrusive changes). Effectively this just enforces a required style, as the order of unpack and named args doesn't matter for the cases where both could be well-defined.

@bwoebi
Copy link
Member

bwoebi commented May 18, 2021

Can we have a test for what happens in case of foo(...["a" => 1], a: 2):? (Also the overwrite-error?)

@nikic nikic force-pushed the named-params-relax branch from dcfca45 to 75cc982 Compare May 18, 2021 12:47
@nikic
Copy link
Member Author

nikic commented May 18, 2021

Can we have a test for what happens in case of foo(...["a" => 1], a: 2):? (Also the overwrite-error?)

Done! Yes, this also results in the overwrite error.

echo $e->getMessage(), "\n";
}
try {
test2(...[1, 'b' => 2], b: 20);
Copy link
Contributor

@mvorisek mvorisek May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about ...[1, 'b' => 2], 20, is it tested anywhere?

Copy link
Member Author

@nikic nikic May 18, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Positional arguments after unpacking are forbidden in general (no relation to named args).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants