Re: [RFC] [DISCUSSION] Scalar Pseudo-type
| From: | Rowan Collins | Date: | Wed, 27 Dec 2017 09:50:54 +0000 |
| Subject: | Re: [RFC] [DISCUSSION] Scalar Pseudo-type | ||
| References: | 1 2 3 4 5 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-101429@lists.php.net to get a copy of this message | ||
On 26 December 2017 18:35:29 GMT+00:00, "lists@rhsoft.net" <lists@rhsoft.net> wrote:
>
>
>Am 26.12.2017 um 19:18 schrieb Larry Garfield:
>> If I may, I think the argument has always been that
>>
>> 1) Foo & Bar makes total sense
>> 2) int|float makes total sense
>> 3) int & string is illogical so wouldn't matter anyway
>
>not true
>
>function x(int|string $x)
>{
> $x = (int)$x;
>}
I think there's a misunderstanding here. Some previous proposals for "union types"
also included "intersection types", so that you could assert "parameter must
implement both of these interfaces". So 'Foo|Bar $x' would mean '$x instanceof
Foo || $x instanceof Bar' and 'Foo&Bar $x' would mean '$x instanceof Foo
&& $x instanceof Bar'.
I presume that's what Larry means by "int & string is illogical", because it
would translate to "is_int($x) && is_string($x)", which is false for all values of
$x. This is different from "int | string", which, as you say, might have valid uses.
Regards,
--
Rowan Collins
[IMSoP]