Le 23/07/2021 à 17:56, Levi Morrison via internals a écrit :
As you note in the RFC, PHP already defines `|` as having a lower
precedence than `&`, so `X & Y | null` can only be interpreted as
`(X & Y) | null`. This is consistent with other languages such as
TypeScript, where `A & B | C & D` is parsed as `(A & B) | (C & D)`.
[2]

Since precedence is already defined for this syntax consistently with
other languages, I don't think it's necessary to require parentheses
if we use the `A & B | null` syntax.
I want to acknowledge and reject this. Few people keep the bitwise
precedence information in their head. It's not worth it -- just
require parenthesis.

I don't want to reject this, this is actually a very good point, do not reinvent a syntax that works somewhere else. And in the end, I do find this readable. (I prey that people will use space in they types definitions to make it even more readable, but style is not a topic for this RFC.)

Accumulating union and sum types is probably not something I'd do every day, so in the end, I'll probably always go and read the documentation each and every time. But for people that do, they'll get used to it fast enough I think.

This behavior seems fine, at least I think it's fine, as long as the documentation is clear.

Regards,

--

Pierre

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

Reply via email to