Re: RFC: Support Closures in constant expressions
| From: | Tim Düsterhus | Date: | Mon, 04 Nov 2024 11:54:49 +0000 |
| Subject: | Re: RFC: Support Closures in constant expressions | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-125899@lists.php.net to get a copy of this message | ||
Hi
Am 2024-10-30 09:31, schrieb Alexandru Pătrănescu:
So, why not allow capturing, since anyway the only place to capture are constants and static variables?Static variables already support arbitrary expressions since https://wiki.php.net/rfc/arbitrary_static_variable_initializers. The RFC initially mentioned static variables as a place where only const-expr would be accepted, but I removed that once I remembered about that other RFC.
And this way we could have short closures with auto-capture. If there are some technical reasons for not doing that, can we have written in the RFC?As stated in the RFC: This constraint is consistent with not supporting variables in constant expressions. Capturing a variable is effectively the same as reading a variable. It makes no sense to support one, but not the other. Best regards Tim Düsterhus