php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #80971 func_get_args() didnt work when using named args
Submitted: 2021-04-20 16:38 UTC Modified: 2021-05-11 06:42 UTC
From: antoni at friki dot cat Assigned:
Status: Open Package: Documentation problem
PHP Version: 8.0.3 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2021-04-20 16:38 UTC] antoni at friki dot cat
Description:
------------
func_get_args() in combination with named args returns an empty array.

Test script:
---------------
<?php

function foo(...$args) {
    //var_dump($args);
    var_dump(func_get_args());
}

foo(a: 9, b: 99, c: 999);


Expected result:
----------------
I expected an array with 3 elements.

Probably:
array(3) {
  ["a"]=>
  int(9)
  ["b"]=>
  int(99)
  ["c"]=>
  int(999)
}

Or:
array(3) {
  [0]=>
  int(9)
  [1]=>
  int(99)
  [2]=>
  int(999)
}

Actual result:
--------------
array(0) {
}

Patches

Add a Patch

Pull Requests

Pull requests:

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-04-20 17:00 UTC] cmb@php.net
-Type: Bug +Type: Documentation Problem -Package: *General Issues +Package: Scripting Engine problem
 [2021-04-20 17:00 UTC] cmb@php.net
This is expected, but apparently undocumented.  From the RFC[1]:

| All three functions are oblivious to the collection of unknown
| named arguments by variadics. func_get_args() will not return the
| collected values and func_num_args() will not include them in the
| argument count. Collected unknown named arguments can only be
| accessed through the variadic parameter.

[1] <https://wiki.php.net/rfc/named_params#func_get_args_and_friends>
 [2021-05-11 06:42 UTC] krakjoe@php.net
-Package: Scripting Engine problem +Package: Documentation problem
 [2021-06-03 02:28 UTC] lufei@php.net
The following pull request has been associated:

Patch Name: Fix 80971: func_get_args() didnt work when using named args
On GitHub:  https://github.com/php/doc-en/pull/650
Patch:      https://github.com/php/doc-en/pull/650.patch
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Jun 13 21:01:24 2021 UTC