Re: RFC: First Class Callables in constant expressions
| From: | Tim Düsterhus | Date: | Wed, 05 Feb 2025 12:17:03 +0000 |
| Subject: | Re: RFC: First Class Callables in constant expressions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-126295@lists.php.net to get a copy of this message | ||
Hi
Am 2025-02-02 15:35, schrieb Rob Landers:
My only concern with the RFC is something a bit silly. If I understand correctly, this will be a constant expression:You understood that correctly.
It is an incredibly small inconsistency (imho), but other than that, ship it.I wouldn't call it an inconsistency, it's natural that the allowed expressions in a constant-expression context are limited. This limitation is mentioned in the second bullet point of the “Constraints” section: Only the "basic form" of first-class callables is supported, mainly to keep the implementation simple, due to the limited usefulness of the more complex function call variants when limited to constant-expressions. As an "escape hatch", it's always possible to wrote a proper closure that just forwards the calls to the desired method. It will also result in a useful error message that is consistent with dynamic new-expressions within const-expr context:
Fatal error: Cannot use dynamic function name in constant expression in test5.php on line 3and for new-expressions:
$ cat test5.php
<?php
const Foo = new (Foo)();
$ sapi/cli/php test5.php
Fatal error: Cannot use dynamic class name in constant expression in test5.php on line 3Best regards Tim Düsterhus