English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

PHP basic tutorial

PHP advanced tutorial

PHP & MySQL

PHP reference manual

PHP get_object_vars() function usage and example

PHP Class/Object function reference manual

The get_object_vars() function returns an associative array composed of object properties

Syntax

get_object_vars($object);

Definition and usage

This function gets the properties of the given object.

Parameter

Serial numberParameters and descriptions
1

object

Object instance.

Return value

Returns an associative array of non-static properties of the specified object in the scope. If no value is assigned to the property, it returns a NULL value.

Online example

The following is the usage of this function-

<?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));
   
   $p1->setLabel("point #1);
   print_r(get_object_vars($p1));
?>
Test and see‹/›

It will produce the following results-

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

PHP Class/Object function reference manual