get_object_vars

get_object_vars -- Retourne un tableau associatif des propriétés d'un objet

Description

array get_object_vars ( object obj)

get_object_vars( ) retourne un tableau associatif contenant les propriétés de l 'objet obj . Les clés du tableau sont les noms des propriétés de l' objet.Si des variables déclarées dans la classe de l'objet obj , n 'ont pas été assignées , elles ne seront pas retournées dans le tableau .

Exemple 1 . Exemple avec get_object_vars( )

 
?php

 
class

 
Point2D

 
{

 
var

 
$x

 
,

 
$y

 
;

 
var

 
$nom

 
;

 
function

 
Point2D($x

 
,

 
$y

 
)

 
{

 
$this

 
-

 
x

 
=

 
$x

 
;

 
$this

 
-

 
y

 
=

 
$y

 
;

 
    }

 
function

 
donne_nom($nom

 
)

 
{

 
$this

 
-

 
nom

 
=

 
$nom

 
;

 
    }

 
function

 
LitPoint(

 
)

 
{

 
return

 
array("x

 
"

 
-

 
$this

 
-

 
x

 
,

 
"y

 
"

 
-

 
$this

 
-

 
y

 
,

 
"nom

 
"

 
-

 
$this

 
-

 
nom)

 
;

 
    }

 
}

 
$p1

 
=

 
new

 
Point2D(1.233

 
,

 
3.445)

 
;

 
print_r(get_object_vars($p1))

 
;

 
/

 
/

 
"$nom

 
"

 
est

 
déclaré

 
,

 
mais

 
non

 
défini

 
/

 
/

 
Array

 
/

 
/

 
(

 
/

 
/

 
[x

 
]

 
-

 
1.233

 
/

 
/

 
[y

 
]

 
-

 
3.445

 
/

 
/

 
)

 
$p1

 
-

 
setnom("point

 
#1")

 
;

 
print_r(get_object_vars($p1))

 
;

 
/

 
/

 
Array

 
/

 
/

 
(

 
/

 
/

 
[x

 
]

 
-

 
1.233

 
/

 
/

 
[y

 
]

 
-

 
3.445

 
/

 
/

 
[nom

 
]

 
-

 
point

 
#1

 
/

 
/

 
)

 
?





Voir aussi get_class_methods( ) et get_class_vars( )