Skip to content

Allow named args after unpack #7009

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed

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