Hi everyone

As foreshadowed in the last e-mail I updated the RFC to restrict the
fetching of properties to enums, and the PR to match it. Unless there
is more feedback I'd like to start the vote early next week.

https://wiki.php.net/rfc/fetch_property_in_const_expressions

---

Hi Claude

> I feel that, in any case, allowing unrestricted fetching properties in const 
> expression in is semantically incorrect, because properties are fundamentally 
> mutable. I am not speaking of creative use of code in order to achieve the 
> effect, but of the regular semantics of properties.
>
> For me, it seems reasonable to restrict the feature to readonly properties 
> (including those of enums), because those are effectively immutable by design.

I thought about this option before the last e-mail. Unfortunately
since readonly properties can be initialized after object construction
the same problem arises. You can find an example here:

https://wiki.php.net/rfc/fetch_property_in_const_expressions#allow_all_readonly_properties

---

Hi Alexandru

> I really think we should have the same limitations for "->" and "?->" just 
> like we have for "new", with the same reason that that was disallowed.
> That would mean not allowing it in the default values of a property.
> Maybe I'm missing something but it looks like this was the plan all along as 
> you don't have any example that would include that, neither in the RFC or in 
> the PR tests.

It was always planned to allow -> in all constant expressions. I added
tests now for all the constant expression positions. Now that only
enums are allowed I don't see a big reason for restricting the scope
any further.

> An option to limit it to enums in the other 3 places, static or instance 
> property initializers and class constant initializers while allowing it on 
> all objects in the 4 cases where new is allowed.
>
> Or yeah, limit to enum in all 7 cases, if that is a lot simpler.
> I wouldn't prefer it as I still have cases in mind where I'm not dealing with 
> enums but it's your call.

I mentioned in the last e-mail that there was an additional problem
regarding caching of constant expression results. I added a section to
the RFC 
(https://wiki.php.net/rfc/fetch_property_in_const_expressions#caching_of_constant_expression_values)
in an attempt to better explain this. I would rather delay support for
other objects until we're confident we have a good solution and
haven't missed any edge cases.

Regards,
Ilija

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php

Reply via email to