Forum und email

get_object_vars

(PHP 4, PHP 5)

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 .

Nota: Nelle versioni di PHP precedenti la 4.2.0, le eventuali variabili dichiarate in nella classe oggetto ma non ancora valorizzate non saranno restituite nell'array. Nelle versioni successive alla 4.2.0, saranno restituite nell'array con valore NULL.

Example#1 Utilizzo di get_object_vars()

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

    function 
Point2D($x$y
    {
        
$this->$x;
        
$this->$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.2333.445);
print_r(get_object_vars($p1));

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

?>

Il precedente esempio visualizzerà:

 
 
Array 
( 
     [x] => 1.233 
     [y] => 3.445 
     [label] =>
) 
    
Array 
( 
     [x] => 1.233 
     [y] => 3.445 
     [label] => point #1 
) 

Vedere anche get_class_methods() e get_class_vars().


pt>