On 19.07.21 11:21, azjezz wrote:
however, when `T` is an intersection between `X` and `T` ( `X&Y` ), `X&Y $x = null` becomes
`null|X&Y $x = null`, which is a combination between union and intersection types, however, as
the RFC stats, currently combination between union and intersection types is not support ( hence
"pure" ).
for this to be allowed, PHP would need to support combining union and intersection
types, preferable using parenthesis ( `X|(Y&Z) $x = null` or `(X&Y)|Z $x =
null` ).
Supporting a syntax like ?A&B could just be a special case just like ?A
was in the past, before actual union types existed. I can see how full
support for union types and intersection types can get complicated (and
may never make it into PHP, or need quite some time until it does), but
pure intersection types that can be nullable seems like a relatively
simple special case which would be very helpful in code, because you
could have optional intersection types in arguments/properties, which is
otherwise not possible (and one would have to fall back once again to
annotations and less type safety).
Nullable intersection types also do not touch upon the main problems of
mixing union types and intersection types, namely in reflection, where
it would just lead to "ReflectionType::allowsNull" to be true instead of
false, but not change any other logic as far as I can tell.
--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: https://www.php.net/unsub.php