PHP get_class_vars() Function

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     classzambiatek{           var$var1= "";            var$var2= "Geeks";                    function__construct(){                $this->var1 ="Articles";                $this->var2 = "zambiatek";                returntrue ;           }     }          $ob= newzambiatek() ;     $array= get_class_vars(get_class($ob));      foreach($arrayas$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     functionformat($array) {         returnimplode('|', array_keys($array)) . "\r\n";     }      classTestCase {         public$a= 1;         protected$b= 2;         private$c= 3;          publicstaticfunctionexpose() {             echoformat(get_class_vars(__CLASS__));         }     }      TestCase::expose();     echoformat(get_class_vars('TestCase')); ?> | 
Output:
a|b|c a
Reference: https://www.php.net/manual/en/function.get-class-vars.php
 
				 
					


