Hi Michał

> Personally, I'd start the discussion on
> https://wiki.php.net/rfc/object_keys_in_arrays instead as this might solve
> the need for
> fetching property in constant expressions.

As mentioned in the RFC, supporting objects as array keys requires
much larger changes in the engine, and also breaks userland
assumptions that array keys can only be of type int|string which means
array functions need to handle object keys accordingly.

For comparison, the "object keys in arrays" RFC is incomplete (changes
for most extensions are missing) and contains ~1300 LOC added and
~1300 removed. All 3rd party PHP extensions would also need to be
updated accordingly. The implementation for this RFC is feature
complete and is at ~160 LOC added.

I actually think both of these RFCs are worthwhile, but since this one
is simpler and does not break userland assumptions it might solve the
problem in a good enough way.

---

HI Alexandru

> I feel that the RFC should be named "Fetch properties in initializers", in 
> sync with https://wiki.php.net/rfc/new_in_initializers
> You explain what "constant expression" means but I feel that using 
> "initialize expression" would be more clear.
> From what I understand, "constant expression" is named like this because 
> until PHP 8.1 it really was a constant.
> And of course because internally this is how the functions in code are named:
> - zend_is_allowed_in_const_expr
> - zend_compile_const_expr
> - zend_const_expr_to_zval
>
> It's unclear how easy it would be to rename them to init_expr instead of 
> const_expr
> but it might be worth it if we consider that "initialize expression" is a 
> better name.

Note that we also use the term constant expression in some error messages.
https://3v4l.org/d2WnS

I intentionally picked a static variable to show that it's not
restricted to consts. But I'm not attached to the term, if it's
clearer for other people I'm happy to switch to "initializer".

Regards,
Ilija

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

Reply via email to