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

search for in the

ReflectionClass::getStaticPropertyValue> <ReflectionClass::getStartLine
[edit] Last updated: Fri, 14 Jun 2013

view this page in

ReflectionClass::getStaticProperties

(PHP 5)

ReflectionClass::getStaticPropertiesRécupère les propriétés statiques

Description

public array ReflectionClass::getStaticProperties ( void )

Récupère les propriétés statiques.

Avertissement

Cette fonction n'est pas documentée et seule la liste des arguments est disponible.

Liste de paramètres

Cette fonction ne contient aucun paramètre.

Valeurs de retour

Les propriétés statiques, sous la forme d'un tableau.

Voir aussi



add a note add a note User Contributed Notes ReflectionClass::getStaticProperties - [1 notes]
up
1
jlennox @ google mail
3 years ago
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.

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