Re: intersection types and null for defaults, proper ties and return types

From: Date: Mon, 19 Jul 2021 14:04:42 +0000
Subject: Re: intersection types and null for defaults, proper ties and return types
References: 1 2  Groups: php.internals 
Request: Send a blank email to internals+get-115490@lists.php.net to get a copy of this message
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

« previous php.internals (#115490) next »