On Mon, Jul 19, 2021, at 4:21 AM, azjezz wrote:
> Hello,
> 
> I personally don't consider a bug, but an expected behavior.
> 
> when writing:
> 
> ```
> T $x = null
> ```
> 
> it is the same as writing:
> 
> ```
> T|null $x = null
> ```
> 
> or
> 
> ```
> ?T $x = null
> ```
> 
> 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` ).
> 
> Regards,
> 
> Saif.

I can see the argument that "I need something with these two interfaces... or 
nothing" is a valid use case to care about.  However, as Saif noted, this is a 
side effect of the inability to mix union and intersection types.

So, my question would be, how feasible will it be in the future to introduce 
that mixing?  If it's something that is likely to show up in 8.2 or 8.3, we may 
be better off going "meh" for now and letting a solution fall out naturally 
later.  If it's something that could take a decade, then figuring out a way to 
special case "or null" in the meantime is probably worthwhile.  (I don't know 
what the best way to do that is.)

--Larry Garfield

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

Reply via email to