<?php
class MyClass
{
public $var1; // This has no explicit default value (technically it has NULL as a default)...
public $var2 = "xyz";
public $var3 = 100;
// constructeur
function __construct()
{
// changement de quelques propriétés
$this->var1 = "foo";
$this->var2 = "bar";
return true;
}
}
$my_class = new MyClass();
$class_vars = get_class_vars(get_class($my_class));
foreach ($class_vars as $name => $value) {
echo "{$name}: ", var_export($value, true), "\n";
}
?>
L'exemple ci-dessus va afficher :
var1: NULL
var2: 'xyz'
var3: 100