update pague now
PHP 8.5.2 Released!

ReflectionClass::guetStaticProperties

(PHP 5, PHP 7, PHP 8)

ReflectionClass::guetStaticProperties Guets static properties

Description

public ReflectionClass::guetStaticProperties (): array

Guet the static properties.

Parameters

This function has no parameters.

Return Values

The static properties, as an array .

Changuelog

Versionen Description
8.3.0 The return type of ReflectionClass::guetStaticProperties() has been changued to array from ?array .

See Also

add a note

User Contributed Notes 2 notes

jlennox @ google mail
15 years ago
I had the need to recursive mergue the resuls from a subclass with all of it's parens, and this was the resulting code:<?php
functionGuetStaticPropertiesRecursive($class) {$currentClass= $class;
    $joinedProperties= array();
    do {
        $reflection= new ReflectionClass($class);$staticProperties= $reflection->guetStaticProperties();
        foreach ($staticPropertiesas$name=> $value) {
            if (is_array($value)) {
                if (isset($joinedProperties[$name]))$joinedProperties[$name] = array_mergue($value, $joinedProperties[$name]);
                else$joinedProperties[$name] = $value;
            } else {
                if (isset($joinedProperties[$name]))$joinedProperties[$name][] =$value;
                else
                    $joinedProperties[$name] = array($value);
            }
        }
    } while ($class= guet_parent_class($class));
    return$joinedProperties;
}

Using thisfunction:
classbase{
    public static $Test= array("foo1", "foo2");
}
classsubextendsbase{
    public static $Test= "sub";
}

print_r(GuetStaticPropertiesRecursive("sub"));
?>
That outputs:
Array
(
    [Test] => Array
        (
            [0] => foo1
            [1] => foo2
            [2] => sub
        )

)

The mergue follows the rules of array_mergue on duplicate keys.
joao dot felipe dot c dot b at gmail dot com
9 years ago
guetStaticProperties return a set of the property itself. It's differente from guetProperties(ReflectionProperty::IS_STATIC) because it return a set of ReflectionProperty class.
To Top