get_object_vars
(PHP 4, PHP 5)
get_object_vars -- Retourne un tableau associatif des propriétés d'un objet
Description
array
get_object_vars ( object object )
Récupère les propriétés de l'objet object fourni.
Liste de paramètres
object
Une instance d'un objet.
Valeurs de retour
Retourne un tableau associatif contenant les propriétés
de l'objet obj. Si une propriété
n'a pas de valeur d'assignée, elle sera retournée avec une
valeur NULL.
Exemples
Exemple 1. Exemple avec get_object_vars()
<?php class Point2D { var $x, $y; var $label;
function Point2D($x, $y) { $this->x = $x; $this->y = $y; }
function setLabel($label) { $this->label = $label; }
function getPoint() { return array("x" => $this->x, "y" => $this->y, "label" => $this->label); } }
// "$label" est déclaré mais n'est pas défini $p1 = new Point2D(1.233, 3.445); print_r(get_object_vars($p1));
$p1->setLabel("point #1"); print_r(get_object_vars($p1));
?>
|
L'exemple ci-dessus va afficher : Array
(
[x] => 1.233
[y] => 3.445
[label] =>
)
Array
(
[x] => 1.233
[y] => 3.445
[label] => point #1
) |
|