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

Reply via email to