php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80387 Wrong behaviour of func_(num|get)_arg(s) functions with named arguments
Submitted: 2020-11-20 13:36 UTC Modified: 2020-11-20 15:26 UTC
From: s dot danilchenko at ttbooking dot ru Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 8.0.0RC5 OS: Windows 10
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.
Password:
Status:
Package:
Bug Type:
Summary:
From: s dot danilchenko at ttbooking dot ru
New email:
PHP Version: OS:

 

 [2020-11-20 13:36 UTC] s dot danilchenko at ttbooking dot ru
Description:
------------
Function cannot fetch its arguments with func_* functions after last one passed by its name.

Test script:
---------------
function test_func($arg1 = 'a', $arg2 = 'b', $arg3 = 'c', $arg4 = 'd')
{
    return json_encode([
        'func_num_args' => func_num_args(),
        'func_get_args' => func_get_args(),
        'direct_args' => [$arg1, $arg2, $arg3, $arg4],
    ], JSON_PRETTY_PRINT);
}

echo test_func(arg1: 'hello', arg3: 'world');


Expected result:
----------------
{
    "func_num_args": 4,
    "func_get_args": [
        "hello",
        "b",
        "world",
        "d"
    ],
    "direct_args": [
        "hello",
        "b",
        "world",
        "d"
    ]
}

Actual result:
--------------
{
    "func_num_args": 3,
    "func_get_args": [
        "hello",
        "b",
        "world"
    ],
    "direct_args": [
        "hello",
        "b",
        "world",
        "d"
    ]
}

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-11-20 15:26 UTC] requinix@php.net
-Status: Open +Status: Not a bug
 [2020-11-20 15:26 UTC] requinix@php.net
This is deliberate.
https://wiki.php.net/rfc/named_params#func_get_args_and_friends

Note that the func_* functions have always reported how the function was *called*, not how the arguments were received. With regular positional arguments, omitting an optional argument is reflected in their return values. https://3v4l.org/V1084
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 18 19:01:30 2024 UTC