get_object_vars
(PHP 4, PHP 5, PHP 7)
get_object_vars — Gets the properties of the given object
Description
$object
) : array
Gets the accessible non-static properties of the given
object
according to scope.
Return Values
Returns an associative array of defined object accessible non-static properties
for the specified object
in scope. If a property has
not been assigned a value, it will be returned with a NULL
value.
Changelog
Version | Description |
---|---|
5.3.0 |
This function now returns NULL if the
object isn't an object. Previously FALSE was returned.
|
Examples
Example #1 Use of get_object_vars()
<?php
class foo {
private $a;
public $b = 1;
public $c;
private $d;
static $e;
public function test() {
var_dump(get_object_vars($this));
}
}
$test = new foo;
var_dump(get_object_vars($test));
$test->test();
?>
The above example will output:
array(2) { ["b"]=> int(1) ["c"]=> NULL } array(4) { ["a"]=> NULL ["b"]=> int(1) ["c"]=> NULL ["d"]=> NULL }
See Also
- get_class_methods() - Gets the class methods' names
- get_class_vars() - Get the default properties of the class
English translation
You have asked to visit this site in English. For now, only the interface is translated, but not all the content yet.If you want to help me in translations, your contribution is welcome. All you need to do is register on the site, and send me a message asking me to add you to the group of translators, which will give you the opportunity to translate the pages you want. A link at the bottom of each translated page indicates that you are the translator, and has a link to your profile.
Thank you in advance.
Document created the 30/01/2003, last modified the 26/10/2018
Source of the printed document:https://www.gaudry.be/en/php-rf-get-object-vars.html
The infobrol is a personal site whose content is my sole responsibility. The text is available under CreativeCommons license (BY-NC-SA). More info on the terms of use and the author.
References
These references and links indicate documents consulted during the writing of this page, or which may provide additional information, but the authors of these sources can not be held responsible for the content of this page.
The author This site is solely responsible for the way in which the various concepts, and the freedoms that are taken with the reference works, are presented here. Remember that you must cross multiple source information to reduce the risk of errors.