get_object_vars

get_object_vars -- Vrátit asociativní pole vlastností objektu

Popis

array get_object_vars ( object obj)

Tato funkce vrací asociativní pole definovaných vlastností objektu obj . Proměnným deklarovaným v třídě jíž je obj instancí , kterým nebyla přiřazena hodnota , nejsou ve vráceném poli obsaženy .

Příklad 1 . Použití 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)

 
;

 
    }

 
}

 
$p1

 
=

 
new

 
Point2D(1.233

 
,

 
3.445)

 
;

 
print_r(get_object_vars($p1))

 
;

 
/

 
/

 
"$label

 
"

 
is

 
declared

 
but

 
not

 
defined

 
/

 
/

 
Array

 
/

 
/

 
(

 
/

 
/

 
[x

 
]

 
=

 
1.233

 
/

 
/

 
[y

 
]

 
=

 
3.445

 
/

 
/

 
)

 
$p1

 
-

 
setLabel("point

 
#1")

 
;

 
print_r(get_object_vars($p1))

 
;

 
/

 
/

 
Array

 
/

 
/

 
(

 
/

 
/

 
[x

 
]

 
=

 
1.233

 
/

 
/

 
[y

 
]

 
=

 
3.445

 
/

 
/

 
[label

 
]

 
=

 
point

 
#1

 
/

 
/

 
)

 

?





Viz také get_class_methods( ) , get_class_vars( )