Iterable objects and array type hinting?

andycobra

New Member
I have a lot of functions that either have type hinting for arrays or use \[code\]is_array()\[/code\] to check the array-ness of a variable. Now I'm starting to use objects that are iterable. They implement \[code\]Iterator\[/code\] or \[code\]IteratorAggregate\[/code\]. Will these be accepted as arrays if they pass through type hinting, or undergo \[code\]is_array()\[/code\]? If I have to modify my code, is there a generic sort of \[code\]is_iterable()\[/code\], or must I do something like:\[code\]if ( is_array($var) OR $var instance_of Iterable OR $var instanceof IteratorAggregate ) { ... }\[/code\]What other iterable interfaces are out there?
 
Back
Top