PHP 7.1 added the new is_iterable function to check whether a variable can be iterated. But although you may iterate over an objects properties is_iterable returns false for them.
This seems to be intentional, as it is documented and I couldn't find any PHP bugs regarding the issue but I wonder why this was done?
<?php
$a = new stdClass();
$a->foo = 'bar';
var_dump(is_iterable($a));
foreach ($a as $key => $value) {
var_dump($key, $value);
}
Outputs
boolean false
string 'foo' (length=3)
string 'bar' (length=3)
But I would expect it to output
boolean true
string 'foo' (length=3)
string 'bar' (length=3)