On 13.06.2016 at 17:59, Levi Morrison wrote: > On Mon, Jun 13, 2016 at 5:42 AM, Christoph Becker <cmbecke...@gmx.de> wrote: >> On 11.06.2016 at 01:37, Aaron Piotrowski wrote: >>> I would like to propose a new iterable pseudo-type that accepts both arrays >>> and objects implementing Traversable. Values accepted by iterable can then >>> be used with foreach and yield from, or help to reduce type-checking logic >>> in general. >>> >>> Please review the RFC here: https://wiki.php.net/rfc/iterable >>> <https://wiki.php.net/rfc/iterable> >> >> Thanks, Aaron! I definitely like this idea (I'm not sure about the >> details yet – would have to thoroughly investigate), as it is apparently >> solving a long-standing issue, and is in my opinion a cleaner solution >> than (explicitly) having to resort to a union type. > > My opinion is contrary: the union type is the cleaner solution as it > does not require special casing machinery in the engine.
I agree that union types are the cleaner solution with regard to the (C) implementation. I don't think, though, that they are the cleaner solution with regard to PHP code; a developer has to think twice which guarantees a union types gives regarding the allowed operations. For instance, what would Foo|Bar guarantee? I would have to look up both respective definitions and find the intersection – and that still leaves room for errors, as operations with the same name do not guarantee equivalent behavior. The special case of reading and understanding `Traversable|array` might quickly get second nature for developers, but it's still ugly to write and read, in my opinion. -- Christoph M. Becker -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php