Bug #80387 [Opn->Nab]: Wrong behaviour of func_(num|get)_arg(s) functions with named arguments

From: Date: Fri, 20 Nov 2020 15:26:24 +0000
Subject: Bug #80387 [Opn->Nab]: Wrong behaviour of func_(num|get)_arg(s) functions with named arguments
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-230480@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=80387&edit=1

 ID:                 80387
 Updated by:         requinix@php.net
 Reported by:        s dot danilchenko at ttbooking dot ru
 Summary:            Wrong behaviour of func_(num|get)_arg(s) functions
                     with named arguments
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            *General Issues
 Operating System:   Windows 10
 PHP Version:        8.0.0RC5
 Block user comment: N
 Private report:     N

 New Comment:

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


Previous Comments:
------------------------------------------------------------------------
[2020-11-20 13:36:25] 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"
    ]
}


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



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


Thread (2 messages)

« previous php.bugs (#230480) next »