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 tha
Sorry, PHP does not work this way. It has been made for quick'n'easy programming, and so you are not bothered with strict typing, which leaves you in dynamic type hell without any help (like a type inferencing compiler). The PHP interpreter is completely clueless about what you have put into your array, so it must iterate over all array entries if it wanted to validate something like the following (which is not working in PHP, of course):
function bar(Foo[] $myFoos)
This is a major impact on performance when the array gets large. I think that's the reason why PHP doesn't offer typed array hints.
The other answers here suggest that you create your strongly typed array wrapper. Wrappers are fine when you have a compiler with generic typing like Java or C#, but for PHP, I disagree. Here, those wrappers are tedious boilerplate code and you need to create one for every typed array. If you want to use array functions from the library, you need to extend your wrappers with type checking delegation functions and bloat your code. This can be done in an academic sample, but in a production system with many classes and collections, where developer time is costly and the MIPS in the web cluster are scarce? I think not.
So, just to have PHP type validation in the function signature, I would refrain from strongly typed array wrappers. I don't believe that the give you enough of a ROI. The PHPDoc support of good PHP IDEs help you more, and in PHPDoc Tags, the Foo[] notation works.
On the other hand, wrappers CAN make sense if you can concentrate some good business logic into them.
Perhaps the day will come when PHP is extended with strongly typed arrays (or more precise: strongly typed dictionaries). I would like that. And with those, they can provide signature hints that don't punish you.