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

[email protected] (AllenJB)
Newsgroups php.internals
Message-ID <[email protected]>
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:

```php
$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:

```php
$params = fn() => [
     "samesite" => "Lax",
     "expires_or_options" => time() + 3600,
     "path" => "/",
     "domain" => "",
     "secure" => false,
     "httponly" => true,
];
```
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.