The get_class_var() function get the default properties of the class. It returns an associative array of declared properties visible from the current scope, with their default value.
Syntax
get_class_vars(name_of_class)
Parameters
name_of_class − The class name
Return
The get_class_vars() function returns an associative array of declared properties visible from the current scope, with their default value. The resulting array elements are in the form of varname => value.
Example
The following is an example −
<?php
class Demo {
var $myvar1 = "xy";
var $myvar2 = "abcd";
var $myvar3 = 7;
var $myvar4 = 20;
var $myvar5 = 90;
private $var4;
function Demo() {
$this->myvar1 = "ab";
$this->myvar2 = "cd";
return true;
}
}
$hello_class = new Demo();
$class_vars = get_class_vars(get_class($hello_class));
foreach ($class_vars as $name => $value) {
echo "$name = $value \n";
}
?>Output
The following is the output −
myvar1 = xy myvar2 = abcd myvar3 = 7 myvar4 = 20 myvar5 = 90