I have a lot of functions that either have type hinting for arrays or use is_array()
to check the array-ness of a variable.
Now I'm starting to use objects that are iterable. They implement Iterator
or IteratorAggregate
. Will these be accepted as arrays if they pass through type hinting, or undergo is_array()
?
If I have to modify my code, is there a generic sort of is_iterable()
, or must I do something like:
if ( is_array($var) OR $var instance_of Iterable OR $var instanceof IteratorAggregate ) { ... }
What other iterable interfaces are out there?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…