Re: [PHP-DEV] [Pre-RFC] Idea: named parameter lists

[email protected] (AllenJB)
Newsgroups php.internals
Message-ID <[email protected]>
On 2026-08-18 10:12, Henrik Skov wrote:
>
> Hi list !
>
> Just got an idea:
>
> params COOKIE_PARAMS {
>     time() + 3600,      // Duration - NOTE: any expression is allowed 
> here except pure variables
>     '/',                          // Path
>     '',                            // Can't remember what this is...
>     (! IS_DEV),            // secure — set true once served over HTTPS 
> (production)
>     TRUE,                    // httpOnly
>     'Lax',                     // Lax|Strict
> }
>
> Instead of this: (I am using Swoole)
>
>         $response->cookie(
>             self::COOKIE_NAME,
>             $token,
>             time() + 3600,
>             '/',
>             '',
>             (! IS_DEV),     // secure — set true once served over HTTPS
>             TRUE,           // httpOnly
>             'Lax',
>         );
>
> we could do:
>
>         $response->cookie(
>             self::COOKIE_NAME,
>             $token,
>             :::COOKIE_PARAMS
>         );
>
> I know it is kind of similar to the spread operator but not quite.
>
> What do you guys think ?Email:
>

PHP already has named parameters[0], and this can be combined with array 
unpacking[1] to produce basically the same as you're requesting here: 
https://3v4l.org/kD27a#v

(Note: I've purposely moved the samesite parameter to prove the named 
array keys are mapping to the named function parameters, and not just 
working because they happen to be in order)

[0] 
https://www.php.net/manual/en/functions.arguments.php#functions.named-arguments
[1] 
https://www.php.net/manual/en/language.types.array.php#language.types.array.unpacking
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.