get_object_vars()
get_object_vars() — Gets the properties of the given object.
Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.
What it does
Gets the accessible non-static properties of the given object according to scope.
Signature
get_object_vars(object $object): array
Parameters
| Parameter | Type | What it takes |
|---|---|---|
| $object | object | An object instance. |
Return value
Returns an associative array of defined object accessible non-static properties for the specified object in scope.
Example
A runnable snippet:
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();
Output:
array(2) { ["b"]=> int(1) ["c"]=> NULL } array(4) { ["a"]=> NULL ["b"]=> int(1) ["c"]=> NULL ["d"]=> NULL }
See also
get_class_methods(), get_class_vars()
All PHP 8.5 built-in functions
Reference card built from the PHP manual page get_object_vars() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.