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

php.internals

Ilija Tovilo

4 years ago
Hi everyone I opened voting for the "Fetch properties of enums in const expressions" RFC. https://wiki.php.net/rfc/fetch_property_in_const_expressions Voting closes on 2022-07-15. Ilija

Michał Brzuchalski

4 years ago
Hi Ilija, pt., 1 lip 2022 o 15:03 Ilija Tovilo <tovilo.ilija@gmail.com> napisał(a):
> Hi everyone > > I opened voting for the "Fetch properties of enums in const expressions" > RFC. > https://wiki.php.net/rfc/fetch_property_in_const_expressions
I voted NO because the originating problem this RFC tries to solve described in https://github.com/php/php-src/issues/8344 is easily solvable by aither 1. introducing a simple constant string value used in both places the enum case and as an attribute value, 2. changing the attribute argument to enum instead. Personally, I'd see using enums as array keys feature first instead (which the RFC reminds in its introductory section as not possible yet) before we start improving places around enums. Best regards, Michał Marcin Brzuchalski

Benjamin Eberlei

4 years ago
> Am 01.07.2022 um 15:03 schrieb Ilija Tovilo <tovilo.ilija@gmail.com>: > > Hi everyone > > I opened voting for the "Fetch properties of enums in const expressions" RFC. > https://wiki.php.net/rfc/fetch_property_in_const_expressions
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.

Ilija Tovilo

4 years ago
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

Ilija Tovilo

4 years ago
Hi everyone
> I opened voting for the "Fetch properties of enums in const expressions" RFC. > https://wiki.php.net/rfc/fetch_property_in_const_expressions > > Voting closes on 2022-07-15.
The RFC has been accepted with 24 yes and 11 no votes. Thanks to everybody who participated! Ilija