get_object_vars

(PHP 4, PHP 5)

get_object_vars -- Gets the properties of the given object

Description

array get_object_vars ( object object )

Gets the properties of the given object.

Parameters

object

An object instance.

Return Values

Returns an associative array of defined object properties for the specified object. If a property have not been assigned a value, it will be returned with a NULL value.

ChangeLog

VersionDescription
prior to 4.2.0 If the variables declared in the class of which the object is an instance, have not been assigned a value, those will not be returned in the array

Examples

Example 1. Use of 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" is declared but not defined
$p1 = new Point2D(1.233, 3.445);
print_r(get_object_vars($p1));

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

?>

The above example will output:

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

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


Follow phpf1 on Twitter




F1 Site Family
AJAX F1
CSS F1
Database F1
Flash F1
HTML F1
Java F1
JavaScript F1
PhotoShop F1
PHP F1
Scripts F1
Tutorial F1
Windows F1

Total time: 0.2283