PHP/Reflection/get object vars — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Версия 10:37, 26 мая 2010
get_object_vars() function returns an array containing the properties of the attributes.
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 <br>";
endwhile;
?>
Obtaining Variable Names
<?
class Shape {
function __construct($numberOfSides = 3, $sideLength = 10)
{
}
$square = new Shape(Shape::NUM_SIDES_SQUARE);
printf("<pre>Shape class variables: %s</pre>",
print_r(get_class_vars("Shape"), TRUE));
printf("<pre>\$square object variables: %s</pre>",
print_r(get_object_vars($square), TRUE));
?>