PHP get_class_vars() Function Last Updated : 28 Apr, 2025 Comments Improve Suggest changes Like Article Like Report The get_class_vars() function is an inbuilt function in PHP which is used to get the default properties of a class. Syntax: array get_class_vars(string $class)Parameters: This function accepts one parameter that is described below: $class: This parameter specifies the name of the class.Return Value: This function returns an associative array like "var name => value" if the get_class_vars() function is successful otherwise it will return "false". Example 1: This example demonstrates the basic use of the get_class_vars() function. PHP <?php class GeeksforGeeks{ var $var1 = "" ; var $var2 = "Geeks" ; function __construct(){ $this->var1 ="Articles" ; $this->var2 = "GeeksforGeeks" ; return true ; } } $ob = new GeeksforGeeks() ; $array = get_class_vars(get_class($ob)); foreach($array as $name => $value){ echo "$name : $value\n"; } ?> Output: var1 : var2 : Geeks Example 2: This is another example that demonstrates the use of the get_class_vars() function. PHP <?php function format($array) { return implode('|', array_keys($array)) . "\r\n"; } class TestCase { public $a = 1; protected $b = 2; private $c = 3; public static function expose() { echo format(get_class_vars(__CLASS__)); } } TestCase::expose(); echo format(get_class_vars('TestCase')); ?> Output: a|b|c a Reference: https://www.php.net/manual/en/function.get-class-vars.php Create Quiz Comment N neeraj3304 Follow 0 Improve N neeraj3304 Follow 0 Improve Article Tags : PHP PHP-function PHP-Classes/Object-Functions Explore BasicsPHP Syntax4 min readPHP Variables5 min readPHP | Functions6 min readPHP Loops4 min readArrayPHP Arrays5 min readPHP Associative Arrays4 min readMultidimensional arrays in PHP5 min readSorting Arrays in PHP4 min readOOPs & InterfacesPHP Classes2 min readPHP | Constructors and Destructors5 min readPHP Access Modifiers4 min readMultiple Inheritance in PHP4 min readMySQL DatabasePHP | MySQL Database Introduction4 min readPHP Database connection2 min readPHP | MySQL ( Creating Database )3 min readPHP | MySQL ( Creating Table )3 min readPHP AdvancePHP Superglobals6 min readPHP | Regular Expressions12 min readPHP Form Handling4 min readPHP File Handling4 min readPHP | Uploading File3 min readPHP Cookies9 min readPHP | Sessions7 min read Like