Re: [RFC][Voting] Fetch properties of enums in const expressions

From: Date: Wed, 06 Jul 2022 23:10:42 +0000
Subject: Re: [RFC][Voting] Fetch properties of enums in const expressions
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-118212@lists.php.net to get a copy of this message
Hi Benjamin > I voted no, because this introduces a special case in const expressions that is hard to explain > and seeing it in the wild will give code readers ideas on property access in consts that will never > be generalizable. > > Imho Const expressions should soley be about declaring state not traversing it. Thanks for your viewpoint. We already support quite a few non-trivial operations in constant expressions. A few examples: * Array offset fetch * Coalesce * Ternary * && and || * new Array offset fetches are essentially the equivalent of -> on arrays. ``` // This is ok const C = ['value' => 'b']['value']; // But this is not? const C = A::B->value; ``` The two cases semantically seem quite similar. I do agree that it's unfortunate that -> isn't allowed on all objects at the moment. But the issues mentioned in the RFC are solvable, although they require more caution, time and thought. Since they weren't relevant to the use case this RFC is trying to solve they were excluded. It's also worth noting that enums are most likely the primary type of object you'll find in constant expressions. Regards, Ilija

« previous php.internals (#118212) next »