- get_object_vars: documentation ( source)
<?php
class Car
{
var $color;
function Car($color="green") {
$this->color = $color;
}
function what_color() {
return $this->color;
}
}
function print_vars($obj) {
foreach (get_object_vars($obj) as $prop => $val) {
echo "\t$prop = $val\n";
}
}
// instantiate one object
$herbie = new Car("white");
$free = new car("blue");
// show herbie properties
echo "\herbie: Properties\n";
print_vars($herbie);
echo "\free: properties\n";
print_vars($free);