$classObject = new MyClass();
foreach ($classObject as $item) {}
<?php
class MyClass
{
public $public = 'значение 1';
protected $protected = 'защищённая переменная';
private $private = 'закрытая переменная';
public function iterateAll() {
foreach ($this as $key => $value) {
print "$key => $value\n";
}
}
}
$class = new MyClass();
$class->iterateAll();