downloads | documentation | faq | getting help | mailing lists | licenses | wiki | reporting bugs | php.net sites | conferences | my php.net

search for in the

ReflectionClass::getDocComment> <ReflectionClass::getConstructor
[edit] Last updated: Fri, 24 May 2013

view this page in

ReflectionClass::getDefaultProperties

(PHP 5)

ReflectionClass::getDefaultProperties获取默认属性

说明

public array ReflectionClass::getDefaultProperties ( void )

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

参数

此函数没有参数。

返回值

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

范例

Example #1 ReflectionClass::getDefaultProperties() 例子

<?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());
?>

以上例程会输出:

array(5) {
   ["staticProperty"]=>
   string(14) "staticProperty"
   ["property"]=>
   string(15) "propertyDefault"
   ["privateProperty"]=>
   string(22) "privatePropertyDefault"
   ["defaultlessProperty"]=>
   NULL
   ["inheritedProperty"]=>
   string(16) "inheritedDefault"
}

参见



add a note add a note User Contributed Notes ReflectionClass::getDefaultProperties - [2 notes]
up
0
runaurufu AT gmail.com
1 year ago
Worth noting that it will not return private parameters of parent class...
so it works exactly as get_class_vars or get_object_vars
up
0
captainjester at hotmail dot com
3 years ago
This will return all properties in a class and any parent classes.  The array will have keys set to the property names and empty values.

 
show source | credits | stats | sitemap | contact | advertising | mirror sites