Search DaTutorials:  
HOME
Php Tutorials
Articles
Basics
Date and Time
File Manipulations
Forms
Functions
General
Interactivity
MySql
Navigation
News,Shoutboxes and Blogs
Language Structure and Data Types
Searching
Security
String Manipulation
User Information and Stats
Search For a Tutorial
Php Reference

get_object_vars

(PHP 4 , PHP 5)

get_object_vars -- Returns an associative array of object properties

Description

array get_object_vars ( object obj)

This function returns an associative array of defined object properties for the specified object obj.

Note: In versions prior to PHP 4.2.0, if the variables declared in the class of which the obj is an instance, have not been assigned a value, those will not be returned in the array. In versions after PHP 4.2.0, the key will be assigned with a NULL value.

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 printout of the above program will be:

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

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

See also get_class_methods() and get_class_vars().



Copyright © 2001-2004 The PHP Group
All rights reserved.

     Mortgages | e Harmony | Credit Cards | Venta de libro | Loans
Home     Link To Us     Ad With Us     Contact Us     Tell A Friend     Affiliates     Blog     MsOfficeHelp