PHP/Reflection/get object vars
get_object_vars() function returns an array containing the properties of the attributes.
<source lang="html4strict">
Its syntax is: array get_object_vars (object obj_name) //Obtaining object variables
<? class car {
var $doors; var $wheels; function car($doors, $wheels) { $this->doors = $doors; $this->wheels = $wheels; } function get_wheels() { return $this->wheels; }
} $toyota = new car(2,400); $vars = get_object_vars($toyota); while (list($key, $value) = each($vars)) :
print "$key ==> $value
";
endwhile; ?>
</source>
Obtaining Variable Names
<source lang="html4strict">
<? class Shape { function __construct($numberOfSides = 3, $sideLength = 10) { } $square = new Shape(Shape::NUM_SIDES_SQUARE);
printf("Shape class variables: %s",
print_r(get_class_vars("Shape"), TRUE));
printf("\$square object variables: %s",
print_r(get_object_vars($square), TRUE)); ?>
</source>