Bug #80327 [Opn->Ver]: Conflicts of parameter names and forwarded variadics
| From: | nikic@php.net | Date: | Mon, 09 Nov 2020 09:47:53 +0000 |
| Subject: | Bug #80327 [Opn->Ver]: Conflicts of parameter names and forwarded variadics | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-230217@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80327&edit=1
ID: 80327
Updated by: nikic@php.net
Reported by: david at grudl dot com
Summary: Conflicts of parameter names and forwarded variadics
-Status: Open
+Status: Verified
Type: Bug
Package: Scripting Engine problem
PHP Version: 8.0.0RC3
Block user comment: N
Private report: N
New Comment:
Nice catch! I don't think we will address this for PHP 8.0, but generally agree that the rules
around named parameters in conjunction with variadics should probably be relaxed.
There is also the related problem, independent of the forwarding use-case, that it's not really
possible to use positional variadics in conjunction with named parameters. That is, doing something
like this is not legal:
array_push(array: $bar, 1, 2, 3)
Again, we could allow collecting the extra positional arguments into the variadic here.
Previous Comments:
------------------------------------------------------------------------
[2020-11-06 13:25:37] david at grudl dot com
Description:
------------
I quote directly from RFC: https://wiki.php.net/rfc/named_params
> One of the primary use-cases for that variadic/unpacking syntaxes is forwarding of arguments.
> The support for named arguments in both variadics and argument unpacking ensures that this pattern
> will continue to work once named arguments are introduced.
function passthru(callable $c, ...$args) {
return $c(...$args);
}
Unfortunately, there is one limitation for forwarding at this time. You cannot pass argument with
key 'c' to $args because it conflicts with parameter $c. So this
passthru($callable, $args);
May throws "Uncaught Error: Named parameter $c overwrites previous argument." depending on
the content of (the otherwise valid) $args.
How to solve it?
A possible solution is to use a very non-conflicting name for $c, for example passthru(callable
$ââ, ...$args), but I think that a better solution would be to ignore the conflicts if
positional parameters are passed and variadics follows.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=80327&edit=1