Re: Improving PHP's type system
| From: | Lin Yo-An | Date: | Fri, 15 Apr 2016 17:16:30 +0000 |
| Subject: | Re: Improving PHP's type system | ||
| References: | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92344@lists.php.net to get a copy of this message | ||
Andrea Faulds <ajf@ajf.me> 於 2016年4月15日 星期五寫道:
>
>
> This is something that particularly concerns me about union types, in that
> they reduce type safety. If you have a union type of Foo|Bar for some
> variable, then the set of methods you can call on that variable is actually
> the intersection, not the union, of the set of methods you can call on Foo
> and Bar. Which, unless those two classes share some interface, is probably
> an empty set. So there's nothing you can actually do safely with it without
> doing checks within the body of the function, and if you're doing that,
> then why do we have a type declaration? It's only barely more useful than
> omitting a type declaration at all; type declarations are supposed to
> prevent you needing to check. On the other hand, if the two classes share
> some methods, then either there's an interface you can already use here, or
> you can create one. Either way, you don't need a union type.
+1 I agree. Language like Golang use interface to intersect the method
calls, I think that's better.
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
Sent from Gmail Mobile