Type hinting - specify an array of objects

Viewed 44695

How can I specify the argument type as an array? Say I have a class named 'Foo':

class Foo {}

and then I have a function that accepts that class type as an argument:

function getFoo(Foo $f) {}

When I pass in an array of 'Foo's I get an error, saying:

Catchable fatal error: Argument 1 passed to getFoo() must be an instance of Foo, array given

Is there a way to overcome this issue? maybe something like

function getFoo(Foo $f[]) {}
5 Answers
class Foo {
    /**
     * @param Foo[] $f
     */
    function getFoo($f) {

    }
}
Related