PHP 8.3.0 RC 6 available for testing

get_mangled_object_vars

(PHP 7 >= 7.4.0, PHP 8)

get_mangled_object_vars返回将对象属性混在一起的数组

说明

get_mangled_object_vars(object $object): array

返回 array,其元素是 object 的属性。key 是成员变量名,但有几个显著的异常:private 变量的变量名前加上类名,protected 变量的变量名前面加上 * 号。这些前置值在两边都带有 NUL 字节。未初始化的类型属性会默默丢弃。

参数

object

对象实例。

返回值

返回包含 object 的所有属性的 array,无论其可见性如何。

示例

示例 #1 get_mangled_object_vars() 示例

<?php

class A
{
public
$public = 1;

protected
$protected = 2;

private
$private = 3;
}

class
B extends A
{
private
$private = 4;
}

$object = new B;
$object->dynamic = 5;
$object->{'6'} = 6;

var_dump(get_mangled_object_vars($object));

class
AO extends ArrayObject
{
private
$private = 1;
}

$arrayObject = new AO(['x' => 'y']);
$arrayObject->dynamic = 2;

var_dump(get_mangled_object_vars($arrayObject));

以上示例会输出:

 
array(6) {
  ["Bprivate"]=>
  int(4)
  ["public"]=>
  int(1)
  ["*protected"]=>
  int(2)
  ["Aprivate"]=>
  int(3)
  ["dynamic"]=>
  int(5)
  [6]=>
  int(6)
}
array(2) {
  ["AOprivate"]=>
  int(1)
  ["dynamic"]=>
  int(2)
}

参见

add a note

User Contributed Notes

There are no user contributed notes for this page.
To Top