首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

ReflectionClass::getDefaultProperties

(PHP 5, PHP 7)

ReflectionClass::getDefaultProperties - 获取默认属性

描述

代码语言:javascript
复制
public array ReflectionClass::getDefaultProperties ( void )

从类获取默认属性(包括继承属性)。

注意:此方法仅适用于在内部类上使用时的静态属性。在用户定义的类上使用此方法时,无法跟踪静态类属性的默认值。

参数

该函数没有参数。

返回值

一组默认属性,其中键是属性的名称,值是属性的默认值,或者NULL属性没有默认值。该函数不区分静态和非静态属性,也不考虑可见性修饰符。

示例

示例#1 ReflectionClass::getDefaultProperties()示例

代码语言:javascript
复制
<?php
class?Bar?{
????protected?$inheritedProperty?=?'inheritedDefault';
}

class?Foo?extends?Bar?{
????public?$property?=?'propertyDefault';
????private?$privateProperty?=?'privatePropertyDefault';
????public?static?$staticProperty?=?'staticProperty';
????public?$defaultlessProperty;
}

$reflectionClass?=?new?ReflectionClass('Foo');
var_dump($reflectionClass->getDefaultProperties());
?>

上面的例子将输出:

代码语言:javascript
复制
array(5) {
   ["staticProperty"]=>
   string(14) "staticProperty"
   ["property"]=>
   string(15) "propertyDefault"
   ["privateProperty"]=>
   string(22) "privatePropertyDefault"
   ["defaultlessProperty"]=>
   NULL
   ["inheritedProperty"]=>
   string(16) "inheritedDefault"
}

另请参阅

  • ReflectionClass::getProperties() - 获取属性
  • ReflectionClass::getStaticProperties() - 获取静态属性
  • ReflectionClass::getProperty() - 获取类的属性的ReflectionProperty

← ReflectionClass::getConstructor

ReflectionClass::getDocComment →

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com