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 3

and 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 3

Best regards
Tim Düsterhus

Reply via email to