在 PHP 中,attributes()
函数用于获取对象的属性列表。
语法:
attributes(object $object): array
参数:
$object
:必需,要获取属性列表的对象。返回值:
示例:
class Person {
private $name;
private $age;
public function __construct($name, $age) {
$this->name = $name;
$this->age = $age;
}
}
$person = new Person("John", 30);
$attributes = attributes($person);
print_r($attributes);
输出:
Array
(
[0] => ReflectionAttribute Object
(
[name] => ReflectionAttribute
[isDefault] =>
[arguments] => Array
(
)
)
[1] => ReflectionAttribute Object
(
[name] => ReflectionAttribute
[isDefault] =>
[arguments] => Array
(
)
)
)
上面的示例中,attributes()
函数返回了一个包含两个 ReflectionAttribute 对象的数组,这些对象表示了 $person
对象的两个属性。
上一篇:php怎么替换空格
下一篇:php怎么实现时间格式转换
Laravel PHP 深圳智简公司。版权所有©2023-2043 LaravelPHP 粤ICP备2021048745号-3
Laravel 中文站