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

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

Reply via email to