NOTE: While objects and arrays can be traversed by foreach, they do NOT implement "Traversable", so you CANNOT check for foreach compatibility using an instanceof check.
Example:
$myarray = array('one', 'two', 'three');
$myobj = (object)$myarray;
if ( !($myarray instanceof \Traversable) ) {
print "myarray is NOT Traversable";
}
if ( !($myobj instanceof \Traversable) ) {
print "myobj is NOT Traversable";
}
foreach ($myarray as $value) {
print $value;
}
foreach ($myobj as $value) {
print $value;
}
Output:
myarray is NOT Traversable
myobj is NOT Traversable
one
two
three
one
two
three