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
Sr.No | Parameter & Description |
---|---|
1 |
class_name(Required) The class name. |
Return Value
It 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 −
Live Demo<?php class helloworld { var $var1; var $var2 = "xyz"; var $var3 = 100; private $var4; // PHP 5 function helloworld() { $this->var1 = "foo"; $this->var2 = "bar"; return true; } } $hello_class = new helloworld(); $class_vars = get_class_vars(get_class($hello_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
Advertisements