PHP | get_class_vars() Function
November 10, 2020
Hello dear readers! welcome back to another edition of our tutorial on PHP. In this tutorial guide, we are going to be discussing about the get_class_vars() Function in PHP.
The get_class_vars() function gets the default properties of the given class. Returns an associative array of default public properties of the class.
The get_class_vars() function gets the default properties of the given class. Returns an associative array of default public properties of the class.
Syntax
Following below is the syntax to use this function -
get_class_vars ( $class_name );
RECOMMENDED POST: PHP | get_class_methods() Function
Parameter Details
Sr.No | Parameter & Description |
---|---|
1 | class_name(Required) The class name. |
Return Value
It returns an associative array of default public properties of the class. The resulting array elements are in the form of varname=>value.
Example
Try out the below example -
<?php class helloworld { var $var1; var $var2 = "xyz"; var $var3 = 100; private $var4; // PHP 5 function helloworld() { $this->var1 = "foo"; $this->var2 = "bar"; return true; } } $hello_class = new helloworld(); $class_vars = get_class_vars(get_class($hello_class)); foreach ($class_vars as $name => $value) { echo "$name : $value \n"; } ?>
Output
When the above code is executed, it will produce the following result -
var1 : var2 : xyz var3 : 100
RECOMMEDED POST: PHP | Class/Object Functions
Alright guys! This is where we are rounding up for this tutorial post. In our next tutorial guide, we are going to be discussing about the PHP get_class() Functions.
Feel free to ask your questions where necessary and i 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 i 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.