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
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
45 - 29 = ?
Subscribe to this entry?

 
 [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
 [2023-05-06 03:00 UTC] timkeller at aol dot com
(https://moderndogmagazine.com/articles/best-online-dog-training-courses)github.com
 [2023-09-29 06:41 UTC] ta dot nnaowens6 at googlemail dot com
Thanks for sharing this, this is amazing. i like it. (https://github.com)(https://www.subwaygiftcardbalance.online/)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 20:01:30 2024 UTC