<?php
class MyClass
{
public $var1 = 'valeur 1';
public $var2 = 'valeur 2';
public $var3 = 'valeur 3';
protected $protected = 'variable protégée';
private $private = 'variable privée';
function iterateVisible() {
echo "MyClass::iterateVisible:
";
foreach ($this as $key => $value) {
print "$key => $value
";
}
}
}
$class = new MyClass();
foreach($class as $key => $value) {
print "$key => $value
";
}
echo "
";
$class->iterateVisible();