Re: [RFC][Under discussion] Fetch properties in const expressions
| From: | Ilija Tovilo | Date: | Thu, 02 Jun 2022 12:17:25 +0000 |
| Subject: | Re: [RFC][Under discussion] Fetch properties in const expressions | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117846@lists.php.net to get a copy of this message | ||
Hi Nikita
> This looks like a reasonable addition.
>
> Could there be any expectation that if -> works, ?-> does as well?
Possibly. The implementation was simple enough so I'll add support for
completeness.
---
Hi Côme
> It is not clear to me why this allows using -> on enums but not on other objects.
The RFC *does* allow using -> on all objects. From the RFC:
> As mentioned, the primary motivation for this feature are enums. However, the
> implementation for supporting new is identical and I don't believe
> arbitrarily restricting how -> can be used in this context makes sense.
> Can you clarify why the following is not allowed:
>
> <?php
>
> $a = new Thing();
>
> class C
> {
> protected $b = $a->var;
> static $staticobj = new Thing();
> function f($p = self::$staticobj->var) {}
> }
protected $b = $a->var; is not allowed because there can't be local
variables in the context of context expressions. `function f($p =
self::$staticobj->var) {}` is not allowed because static variables
aren't supported in constant expressions. Your examples would already
fail today without ->.
Ilija