get_object_vars

(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);
    }
}

$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));
// "$label" は宣言されていますが、未定義です。
// 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
// )

? 


get_class_methods() get_class_vars() も参照下さい。