get_object_vars

(PHP 4 )

get_object_vars -- Restituisce un array associativo con le proprietà dell'oggetto

Descrizione

array get_object_vars ( object oggetto)

Questa funzione restituisce un array associativo con le proprietà definite nell'oggetto passato nel parametro oggetto . Le variabili, dichiarate nella classe di cui oggetto è un'istanza, a cui non sia stato ancora assegnato un valore, non saranno restituite nell'array.

Esempio 1. Utilizzo di get_object_vars()

<?php
class Point2D {
    var $x, $y;
    var $etichetta;

    function Point2D($x, $y) {
        $this->x = $x;
        $this->y = $y;
    }

    function setetichetta($etichetta) {
        $this->etichetta = $etichetta;
    }

    function getPoint() {
        return array("x" => $this->x,
                     "y" => $this->y,
                     "etichetta" => $this->etichetta);
    }
}

// "$etichetta" è dichiarata ma non definita
$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));

$p1->setetichetta("point #1");
print_r(get_object_vars($p1));

?>
L'output del programma precedente sarà:
Array 
( 
     [x] => 1.233 
     [y] => 3.445 
) 
    
Array 
( 
     [x] => 1.233 
     [y] => 3.445 
     [label] => point #1 
)

Vedere anche get_class_methods() e get_class_vars()