Bug->Doc #80971 [Opn]: func_get_args() didnt work when using named args

From: Date: Tue, 20 Apr 2021 17:00:23 +0000
Subject: Bug->Doc #80971 [Opn]: func_get_args() didnt work when using named args
References: 1  Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18715@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80971&edit=1

 ID:                 80971
 Updated by:         cmb@php.net
 Reported by:        antoni at friki dot cat
 Summary:            func_get_args() didnt work when using named args
 Status:             Open
-Type:               Bug
+Type:               Documentation Problem
-Package:            *General Issues
+Package:            Scripting Engine problem
 PHP Version:        8.0.3
 Block user comment: N
 Private report:     N

 New Comment:

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>


Previous Comments:
------------------------------------------------------------------------
[2021-04-20 16:38:25] 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) {
}


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=80971&edit=1


Thread (5 messages)

« previous php.doc.bugs (#18715) next »