Benjamin Eberlei wrote on 15/07/2015 21:19:


On Wed, Jul 15, 2015 at 9:53 PM, Rowan Collins <rowan.coll...@gmail.com <mailto:rowan.coll...@gmail.com>> wrote:

    On 15 July 2015 20:39:05 GMT+01:00, Levi Morrison <le...@php.net
    <mailto:le...@php.net>> wrote:
    >Do note that the union types RFC would also alleviate some of this
    >pain for user-land functions, since `array | Traversable` would cover
    >the required access pattern. I think this is a superior approach
    >myself, but I may be a bit biased as I am authoring that proposal:
    >https://wiki.php.net/rfc/union_types

    I like the idea of union types in general, but have always felt
    that a typehint of Traversable should accept arrays as a matter of
    course. The only thing such a typehint guarantees is that foreach
    will work (there are no methods defined that can be called
    directly), and an array meets that condition. The only difference
    I can see is in the passing / mutability behaviour of objects vs
    non-objects.


But instanceof and anything related to Reflection or get_class or relevant code will fail on array.


Ah, yes, I hadn't thought of reflection type things. I don't think instanceof would be a problem, because checking for any class or interface other than Traversable would correctly return false; not sure if it would make sense for "array() instanceof Traversable" to return true or not...

Reply via email to