Jesus · Bible · HTML · CSS · JS · PHP · SVG · Applications

get_class_vars

Description

The get_class_vars of Class / Object for PHP get the default properties of the class.

Syntax

get_class_vars ( string $class_name ) : array

Parameters

class_name

The class name

Return

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. In case of an error, it returns FALSE.

Examples

1

<?

class myclass
{
    public $var1 = "default";
    public $var2 = "default";
    public $var3 = "default";

    function __construct()
    {
        $this->var1 = "change";
        $this->var2 = "change";
        $this->var3 = "change";
    }
}

$class_name = "myclass";

$return = get_class_vars($class_name);

print_r($return);

?>
Array
(
    [var1] => default
    [var2] => default
    [var3] => default
)

2

<?

class myclass
{
    public $var1 = "public";
    protected $var2 = "protected";
    private $var3 = "private";

    public static function myfunction()
    {
        $return = get_class_vars(__CLASS__);

        print_r($return);
    }
}

$class_name = "myclass";

$return = get_class_vars($class_name);

print_r($return);

myclass::myfunction();

?>
Array
(
    [var1] => public
)
Array
(
    [var1] => public
    [var2] => protected
    [var3] => private
)
HomeMenu