PHP | get_object_vars() Function Last Updated : 01 Oct, 2021 Comments Improve Suggest changes Like Article Like Report The get_object_vars() function is an inbuilt function in PHP that is used to get the properties of the given object. When an object is made, it has some properties. An associative array of properties of the mentioned object is returned by the function. But if there is no property of the object, then it returns NULL. Syntax: get_object_vars( $object ) Parameters: This function accepts a single parameter as mentioned above and described below: $object: This parameter holds the object of an instance.Return Value: This method returns an associative array object accessible non-static properties for the specified object in scope. Below programs illustrate the get_object_vars() function in PHP: Program 1: PHP <?php // Declare a class class gfg { // Properties of an object // of this class private $geeks = 0.02; public $for = 1; public $Geeks = "php"; private $GEEKS; static $e; public function example() { var_dump(get_object_vars($this)); } } // Create an object of a class $example = new gfg; // Display properties of the // newly created object var_dump(get_object_vars($example)); $example->example(); ?> Output: array(2) { ["for"]=> int(1) ["Geeks"]=> string(3) "php" } array(4) { ["geeks"]=> float(0.02) ["for"]=> int(1) ["Geeks"]=> string(3) "php" ["GEEKS"]=> NULL } Program 2: PHP <?php // Create a class class coordinate { // The properties of the // object of this class var $x; var $y; var $z; var $labels; function coordinate($x, $y, $z) { $this->x = $x; $this->y = $y; $this->z = $z; } function to_set($labels) { $this->labels = $labels; } } $point1 = new coordinate(0.1, 0.2, 0.3); print_r(get_object_vars($point1)); $point1->to_set("point 1"); print_r(get_object_vars($point1)); ?> Output: Array ( [x] => 0.1 [y] => 0.2 [z] => 0.3 [labels] => ) Array ( [x] => 0.1 [y] => 0.2 [z] => 0.3 [labels] => point 1 ) Reference: https://www.php.net/manual/en/function.get-object-vars.php Comment More infoAdvertise with us Next Article PHP | get_object_vars() Function GeeksforGeeks Improve Article Tags : Web Technologies PHP PHP-function PHP-OOP Similar Reads PHP get_mangled_object_vars() Function The get_mangled_object_vars() function is an inbuilt function in PHP which is used to return an array of mangled object properties. This function returns an array whose elements are the properties of an object. The keys are the member variable. Syntax: array get_mangled_object_vars(object $object) P 1 min read PHP | is_object() Function The is_object() function is an inbuilt function in PHP which is used to check whether the given value is an object or not. Syntax: bool is_object( mixed $var ) Parameters: This function accepts single parameter as mentioned above and described below: $var: It contains the value of variable that need 1 min read 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: 1 min read PHP | get_defined_vars() Function The get_defined_vars() function is an inbuilt function in PHP which is used to returns an array of all defined variables. This function returns a multidimensional array which contains all the list of variables, environment etc. Syntax: array get_defined_vars( void ) Parameters: This function does no 1 min read PHP ob_get_clean() Function The ob_get_clean() function is an in-built PHP function that is used to clean or delete the current output buffer. It's also used to get the output buffering again after cleaning the buffer. The ob_get_clean() function is the combination of both ob_get_contents() and ob_end_clean(). Syntax: string|f 2 min read Like