Re: [RFC][Under discussion] Fetch properties in const expressions
| From: | Alexandru Pătrănescu | Date: | Wed, 15 Jun 2022 17:04:18 +0000 |
| Subject: | Re: [RFC][Under discussion] Fetch properties in const expressions | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-117954@lists.php.net to get a copy of this message | ||
On Wed, Jun 15, 2022 at 6:59 PM Ilija Tovilo <tovilo.ilija@gmail.com> wrote:
> Hi
>
> > Just a question.
> > Would this also be allowed?
> >
> > https://3v4l.org/RGdIA
> > <?php
> >
> > class A {public int $i = 42;}
> > const BARE_CONSTANT = new A;
> > class B {
> > const ClassConstant = BARE_CONSTANT;
> > }
> > class C {
> > const ClassConstantViaPropertyFetching1 = BARE_CONSTANT->i;
> > const ClassConstantViaPropertyFetching2 = B::ClassConstant->i;
> > }
>
> Yes, that would work fine.
>
> Ilija
>
>
Hey, sorry to bump here on this topic.
My assumption was that the use of
-> in initializers would bear the same
limitations as using new.
That would mean it would not be supported for
- class constant initializers
- instance property initializers
- static property initializers
For new clarifications are here:
https://wiki.php.net/rfc/new_in_initializers#unsupported_positions
My assumption is that -> would only work for:
- static variable initializers
- global constant initializers
- parameter default values
- attribute arguments
The examples shared by Shinji are for class constant initializers in class
C and I'm guessing it would not work.
If that's the case, I think we should clarify this in the RFC as well.
Regards,
Alex