I know that iteration over an object is equal to iterating over the visible properties of the class.
class MyClass
{
public $var1 = 'value 1';
public $var2 = 'value 2';
public $var3 = 'value 3';
protected $protected = 'protected var';
private $private = 'private var';
}
$class = new MyClass();
foreach($class as $key => $value) {
print "$key => $value\n"; // print all visible attributes
}
I'm curious to know why iteration over an object that doesn't implement any interface causes iteration over its visible variables? And what is the use case of this ability?