Using named parameters with a variadic parameter
Nobody has claimed this yet.
- Dominant language
- XML
- Stars
- 596
- Forks
- 890
- Avg merge
- 1d 15h
- Merged PRs (30d)
- 55
Description
Description
Consider the following code:
function foo(int $a = 0, int $b = 0, string ...$flags) {}
It is not possible to pass more than one value to $flags when using named parameters:
foo(flags: 'bar'); // valid
foo(flags: 'bar', 'baz'); // Fatal error: Cannot use positional argument after named argument
foo(flags: ['bar', 'baz']); // Fatal error: Uncaught TypeError: foo(): Argument php/php-src#3 must be of type string, array given
foo(flags: ...['bar', 'baz']); // Parse error: syntax error, unexpected token "..."
Additionally, foo(flags: 'bar'); results in the $flags being:
[
'flags': 'bar',
]
Not sure if this is expected but I expected it to be ['bar'].
PHP Version
8.0+
Operating System
No response
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The issue names no documentation file or test; start by locating the PHP 8 documentation for named arguments and variadic parameters. Compare its documented behavior with the supplied foo() examples, and consider the work done when the supported syntax and resulting variadic array keys are explained accurately.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- documentation
- Issue type
- Documentation
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100