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: Online PHP editor | output for kD27a
(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] PHP: Function parameters and arguments - Manual
[1] PHP: Arrays - Manual