Re: [RFC] Patch for Union and Intersection Types
| From: | Bob Weinand | Date: | Tue, 26 Apr 2016 19:13:59 +0000 |
| Subject: | Re: [RFC] Patch for Union and Intersection Types | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92814@lists.php.net to get a copy of this message | ||
> Am 26.04.2016 um 19:41 schrieb Niklas Keller <me@kelunik.com>:
>
> 2016-04-26 19:33 GMT+02:00 Bob Weinand <bobwei9@hotmail.com
> <mailto:bobwei9@hotmail.com>>:
> > Am 26.04.2016 um 19:00 schrieb Niklas Keller <me@kelunik.com
> > <mailto:me@kelunik.com>>:
> >
> > 2016-04-26 16:58 GMT+02:00 Bob Weinand <bobwei9@hotmail.com
> > <mailto:bobwei9@hotmail.com>>:
> >
> >> Yeah, I'd like to not allow ?Foo in any case if union types pass.
> >>
> >
> > What's the reason for that? To me, null is neither a type nor should it be.
>
> I don't want to argue that now, but null most definitely IS a type. It is the null type
> with a single value, null, whose semantics is to represent the absence of any other value.
>
> There's also plenty of evidence in PHP that null is considered a type: get_type(),
> https://php.net/null
> <https://php.net/null>, has it's own is_* function etc.
> At least in the PHP ecosystem it is considered its own type. Other type systems may not, but
> the one of PHP does.
>
> Thus, we are definitely considering it as a type - a question for you: What's the type of
> the value null then, if not null?
>
> I'd say it's special and doesn't have a type at all. No value, no type.
>
> If we wouldn't make a distinction between null and an object (i.e. allow null to be passed
> to a function(Foo $foo) {}), it could be considered a supervalue of type object. But that's not
> the case.
>
> If null doesn't have a type, it's clear that it can't be passed to a
> function(Foo $foo) {}.
There's undefined (= not a value) and there's the value null. We just don't expose
undefined to userland. [You see it when accessing undefined variables, which PHP converts to null
with a notice for example.]
Null is definitely a value. You can pass it around, reflect on it, assign it etc..
And as it is a value, it also has a type, which is null.
Null is not special, it just has specific behavior, like any other primitive type has. The only
special thing is that it's allowed as a default value with function (Foo $foo = null), but this
should be somewhen deprecated and removed once we have proper null unions.
If you want to continue arguing, please open a new thread, but don't side-track this thread to
much, please.
Bob