 |
 |
 |
 |
Warning: include(../levoe_menu.php) [ function.include]: failed to open stream: No such file or directory in /var/www/prime/data/www/prime-speed.ru/Manual_PHP_4/f/get-object-vars.html on line 46
Warning: include() [ function.include]: Failed opening '../levoe_menu.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/prime/data/www/prime-speed.ru/Manual_PHP_4/f/get-object-vars.html on line 46
|
 |
 |
 |
 | |
|  |
(PHP 4)
get_object_vars - возвращает ассоциативный массив из свойств объекта. Описание
array get_object_vars (object obj) Эта функция возвращает ассоциативный массив свойств определённого
специфицированного объекта obj. Если переменным, объявленным в классе, экземпляром которого является
obj, не присвоены значения, они не будут возвращены в этом массиве.
Пример 1. Использование 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" объявлена, но не определена
$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));
$p1->setLabel("point #1");
print_r(get_object_vars($p1));
?> |
|
Эта программа напечатает:
Array
(
[x] => 1.233
[y] => 3.445
)
Array
(
[x] => 1.233
[y] => 3.445
[label] => point #1
) |
См. также get_class_methods() и
get_class_vars(). |  | |
|
 |
 |
 |
 |
Warning: include(../pravoe_menu.php) [ function.include]: failed to open stream: No such file or directory in /var/www/prime/data/www/prime-speed.ru/Manual_PHP_4/f/get-object-vars.html on line 180
Warning: include() [ function.include]: Failed opening '../pravoe_menu.php' for inclusion (include_path='.:/usr/share/php:/usr/share/pear') in /var/www/prime/data/www/prime-speed.ru/Manual_PHP_4/f/get-object-vars.html on line 180
|
 |
 |
 |
 | |