|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80327 Conflicts of parameter names and forwarded variadics
Submitted: 2020-11-06 13:25 UTC Modified: 2020-11-09 09:47 UTC
Avg. Score:4.7 ± 0.5
Reproduced:4 of 5 (80.0%)
Same Version:4 (100.0%)
Same OS:2 (50.0%)
From: david at grudl dot com Assigned:
Status: Verified Package: Scripting Engine problem
PHP Version: 8.0.0RC3 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: david at grudl dot com
New email:
PHP Version: OS:


 [2020-11-06 13:25 UTC] david at grudl dot com
I quote directly from RFC:

> 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-06 14:40 UTC]
-Summary: Conflicts of parameter names and variadics +Summary: Conflicts of parameter names and forwarded variadics -Type: Feature/Change Request +Type: Bug
 [2020-11-09 09:47 UTC]
-Status: Open +Status: Verified
 [2020-11-09 09:47 UTC]
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.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Jun 20 18:01:30 2024 UTC