Hello folks! welcome back to a new edition of our tutorial on PHP. In this tutorial guide, we are going to be studying about the PHP get_object_vars() Function.
The built-in PHP get_object_vars() Function gets the properties of the given object.
The built-in PHP get_object_vars() Function gets the properties of the given object.
Syntax
Following below is the syntax to use this function -
get_object_vars ( $object);
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | object An object instance. |
Return Value
This PHP function returns an associative array of defined object properties for the specified object. If a property have not been assigned a value, it will be returned with a NULL value.
Example
Try out the below example -
<?php class Point2D { var $x, $y; var $label; function Point2D($x, $y) { $this->x = $x; $this->y = $y; } function setLabel($label) { $this->label = $label; } function getPoint() { return array("x" => $this->x, "y" => $this->y, "label" => $this->label); } } $p1 = new Point2D(1.233, 3.445); print_r(get_object_vars($p1)); $p1->setLabel("point #1"); print_r(get_object_vars($p1)); ?>
Output
When the above code is executed, it will produce the following result -
Array ( [x] => 1.233 [y] => 3.445 [label] => ) Array ( [x] => 1.233 [y] => 3.445 [label] => point #1 )
Alright guys! This is where we are going to be rounding up for this tutorial post. In our next tutorial, we are going to be discussing about the get_parent_class() Function.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.
Feel free to ask your questions where necessary and we will attend to them as soon as possible. If this tutorial was helpful to you, you can use the share button to share this tutorial.
Follow us on our various social media platforms to stay updated with our latest tutorials. You can also subscribe to our newsletter in order to get our tutorials delivered directly to your emails.
Thanks for reading and bye for now.