On Thu, Apr 28, 2016 at 4:54 AM, Levi Morrison <le...@php.net> wrote:
> Internals,
>
> As alluded to last week I have another RFC for improving the type
> system: [intersection types][1].
>
> It allows parameters to define multiple type constraints that must be
> satisfied. Common combinations of our built-in types include
> `ArrayAccess & Traversable & Countable` and `Countable & Iterator`.
>
> Some people have suggest I merge this and union types into one RFC.
> For now I'll just proceed with them separately to gain feedback.
>
>   [1]: http://wiki.php.net/rfc/intersection_types
>
> --
> PHP Internals - PHP Runtime Development Mailing List
> To unsubscribe, visit: http://www.php.net/unsub.php
>

To me, it seems that intersection types are more useful than union
types (other than the obvious null|Foo and array|Traversable cases) as
they'd allow us to write smaller interfaces and better follow ISP in
userland, with interfaces becoming much more convenient for
documenting the requirements of a parameter.

At present we tend to have incomplete implementations of interfaces
(e.g. throw OperationNotSupportedException). Union types would allow
us to create more, smaller interfaces and avoid situations where the
type of a parameter doesn't accurately reflect the method's true
requirements, or where concretions are incomplete implementations of
an interface.

Thanks for your efforts, Levi, I'm excited about this one!

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to