[php-src] Issue #10001: Using named parameters with a variadic parameter
| From: | kbond | Date: | Fri, 25 Nov 2022 15:44:10 +0000 |
| Subject: | [php-src] Issue #10001: Using named parameters with a variadic parameter | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-242917@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/10001
Author: kbond
### Description
Consider the following code:
```php
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:
```php
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
#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:
```php
[
'flags': 'bar',
]
```
Not sure if this is expected but I expected it to be ['bar'].
### PHP Version
8.0+
### Operating System
_No response_