文字

ReflectionClass::getStaticProperties

(PHP 5)

ReflectionClass::getStaticProperties获取静态(static)属性

说明

public array ReflectionClass::getStaticProperties ( void )

获取静态(static)属性。

Warning

本函数还未编写文档,仅有参数列表。

参数

此函数没有参数。

返回值

静态(static)的属性,类型是 array

参见

  • ReflectionClass::getStaticPropertyValue() - 获取静态(static)属性的值
  • ReflectionClass::setStaticPropertyValue() - 设置静态属性的值

用户评论:

[#1] jlennox @ google mail [2010-05-08 10:03:02]

I had the need to recursive merge the results from a subclass with all of it's parents, and this was the resulting code:

<?php
function GetStaticPropertiesRecursive($class) {
    
$currentClass $class;
    
$joinedProperties = array();
    do {
        
$reflection = new ReflectionClass($class);
        
$staticProperties $reflection->getStaticProperties();
        foreach (
$staticProperties as $name => $value) {
            if (
is_array($value)) {
                if (isset(
$joinedProperties[$name]))
                    
$joinedProperties[$name] = array_merge($value$joinedProperties[$name]);
                else
                    
$joinedProperties[$name] = $value;
            } else {
                if (isset(
$joinedProperties[$name]))
                    
$joinedProperties[$name][] = $value;
                else
                    
$joinedProperties[$name] = array($value);
            }
        }
    } while (
$class get_parent_class($class));
    return 
$joinedProperties;
}

Using this function:
class 
base {
    public static 
$Test = array("foo1""foo2");
}
class 
sub extends base {
    public static 
$Test "sub";
}

print_r(GetStaticPropertiesRecursive("sub"));
?>


That outputs:
Array
(
    [Test] => Array
        (
            [0] => foo1
            [1] => foo2
            [2] => sub
        )

)

The merge follows the rules of array_merge on duplicate keys.

上一篇: 下一篇: