Hello all,

At present, there's now way to type hint over a generic structure that it
iteratable using foreach(). You can accept arrays using the array hint, and
objects using traversable, but you cannot hint both. This yields code that
wants to accept that to look like this:

function foo($a) {
    if (!is_array($a) && !$a instanceof Traversable) {
        raise error;
    }
}

Would it be worth while adding a new type hint that checks for this
condition? I'd propose Iterable:

function foo(Iterable $a) {
    foreach ($a as ...) {}
}

It's just a quick thought and wanted some feedback on it.

Thanks

Anthony

Reply via email to