array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.get-object-vars.php', 1 => 'get_object_vars', ), 'up' => array ( 0 => 'ref.classobj.php', 1 => '类/对象 函数', ), 'prev' => array ( 0 => 'function.get-mangled-object-vars.php', 1 => 'get_mangled_object_vars', ), 'next' => array ( 0 => 'function.get-parent-class.php', 1 => 'get_parent_class', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/classobj/functions/get-object-vars.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4, PHP 5, PHP 7, PHP 8)
get_object_vars — 获取指定对象的属性
object
对象实例。
返回指定 object
在当前作用域的属性组成的关联数组,属性为已定义、非静态、可访问。
示例 #1 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();
?>
以上示例会输出:
array(2) { ["b"]=> int(1) ["c"]=> NULL } array(4) { ["a"]=> NULL ["b"]=> int(1) ["c"]=> NULL ["d"]=> NULL }
注意:
未初始化的属性认为是不可访问的,因此不会包含在数组中。