PHP - Function get_class_vars()


Advertisements


Syntax

get_class_vars ( $class_name );

Definition and Usage

This function gets the default properties of the given class. Returns an associative array of default public properties of the class.

Parameters

Parameter Description
class_name Required. The class name.

Return Value

Returns an associative array of default public properties of the class. The resulting array elements are in the form of varname => value.

Example

Following is the usage of this function −

<?php
   class myclass {
      var $var1;
      var $var2 = "xyz";
      var $var3 = 100;
      private $var4; // PHP 5
      
      function myclass() {
         $this->var1 = "foo";
         $this->var2 = "bar";
         return true;
      }
   }
	
   $my_class = new myclass();
   $class_vars = get_class_vars(get_class($my_class));
   
   foreach ($class_vars as $name => $value) {
      echo "$name : $value \n";
   }
?> 

It will produce the following result −

var1 :
var2 : xyz
var3 : 100

php_function_reference.htm