Re: intersection types and null for defaults, properties and return types
| From: | Deleu | Date: | Tue, 20 Jul 2021 19:19:43 +0000 |
| Subject: | Re: intersection types and null for defaults, properties and return types | ||
| References: | 1 2 3 4 5 6 7 8 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-115538@lists.php.net to get a copy of this message | ||
On Tue, Jul 20, 2021, 20:35 Niklas Keller <me@kelunik.com> wrote:
> >
> > > > > nicolas-grekas wrote on the PR:
> > > > > > ?X&Y cannot be confused with
> > > > >
> > > > > It confused me. A compiler might understand it, but as a human I
> have
> > > > > trouble understanding it.
> >
>
> I think ?X&Y would be a pretty poor syntax choice, as it's ambiguous as
> many others said: (X|null)&(Y) vs. (X&Y)|null.
>
> What hasn't been proposed, yet, is ?X&?Y, so requiring either all or none
> of the types being nullable.
>
> Best,
> Niklas
>
From the look of the syntax I would prefer it not to land on 8.1 at all,
which gives us another year to think of any syntax less aggressive to the
eyes.
One of the things I loved about the Pure Intersection RFC was that it
avoided the discussion around parenthesis on type declaration altogether.
Maybe if a type alias is proposed before mingling Union and Intersection,
then it's less of an aggressive syntax.
Type T = (X&Y)|Z|null
I don't know if anyone has offered this before, but if making an exception
for nullable Intersection is on the table, what about putting the null sign
at the end?
X&Y&Z?
It doesn't seem ambiguous because PHP defines ?X as nullable X. It doesn't
seem obvious what the ? is doing at the end but at least it doesn't seem
ambiguous.
>