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

From: Date: Tue, 18 Aug 2026 14:07:30 +0000
Subject: Re: [Pre-RFC] Idea: named parameter lists
References: 1 2 3 4 5 6 7  Groups: php.internals 
Request: Send a blank email to internals+get-132259@lists.php.net to get a copy of this message
On 18/08/2026 14.17, Kamil Tekiela wrote:
On Tue, 18 Aug 2026 at 12:35, Henrik Skov<henry.wood.dk@gmail.com> wrote:
On 18/08/2026 12.52, AllenJB wrote: On 2026-08-18 11:02, Henrik Skov wrote: Hi again ! The important part is that any instantiations and function calls are evaluated at call-time and not compile time ! So time() would return the timestamp at time of call and not when compiler first encounters the COOKIE_PARAMS const array. The new params keyword would make this clear to the compiler /Henrik On 18/08/2026 11.43, Henrik Skov wrote: Thanks for the feedback. Problem with your re-written example is that it works with/depends on global variables... I was the code below actually worked: <?php const COOKIE_PARAMS = [
     "samesite"                 => "Lax",
     "expires_or_options"     => time() + 3600,     // Let's say time is 1787047184
     "path"                     => "/",
     "domain"                 => "",
     "secure"                 => false,
     "httponly"                 => true,
]; [...]
sleep(100); var_dump(time()); // -> 1787047284 fakeSetCookie("testName", "testValue", ...COOKIE_PARAMS); so expires_or_options become 1787050884
Ah, I think I understand now. What you're proposing is a structure where you can define a value as an expression, and that expression is only evaluated when the structure is used (rather than when it's defined). So, even in a long-lived application, the expires_or_options value would always be evaluated as time() + 3600 If this were to be implemented, I think it would be better to look at values, rather than defining an entire structure. I can see it being used for more than parameters. Something like an IIFE that's invoked when used rather than when defined. As a side-note, one way to achieve this in current PHP would be to use a callable:
$params = function() {
     return [
         "samesite" => "Lax",
         "expires_or_options" => time() + 3600,
         "path" => "/",
         "domain" => "",
         "secure" => false,
         "httponly" => true,
     ];
};

fakeSetCookie("testName", "testValue", ...$params());
sleep(2);
fakeSetCookie("testName", "testValue", ...$params());
(3v4l refused to save this, probably because it takes too long) This can also be written using arrow functions:
$params = fn() => [
     "samesite" => "Lax",
     "expires_or_options" => time() + 3600,
     "path" => "/",
     "domain" => "",
     "secure" => false,
     "httponly" => true,
];
-- Yes, but I think one should consider params COOKIE_PARAMS {...} more of a type !
Then why not create a type for ithttps://3v4l.org/lNjSX#vgit.master -- Because it is not worthy of a full class. By the same logic, why do we have enums ? A class of constants works just as fine as an enum ? Maybe I shouldn't have said 'type' - What I meant was language construct I think Med venlig hilsen Henrik Skov /HSK Consulting/ Blegdamsvej 128B, 4 DK-2100 Copenhagen O Tel.: +45 27 62 83 01 Email: henry.wood.dk@gmail.com


« previous php.internals (#132259) next »