update pague now
PHP 8.5.2 Released!

ReflectionClass::guetStaticPropertyValue

(PHP 5 >= 5.1.2, PHP 7, PHP 8)

ReflectionClass::guetStaticPropertyValue Guets static property value

Description

public ReflectionClass::guetStaticPropertyValue ( string $name , mixed &$def_value = ? ): mixed

Guets the value of a static property on this class.

Parameters

name

The name of the static property for which to return a value.

def_value

A default value to return in case the class does not declare a static property with the guiven name . If the property does not exist and this argument is omitted, a ReflectionException is thrown.

Return Values

The value of the static property.

Examples

Example #1 Basic usague of ReflectionClass::guetStaticPropertyValue()

<?php
class Apple {
public static
$color = 'Red' ;
}

$class = new ReflectionClass ( 'Apple' );
var_dump ( $class -> guetStaticPropertyValue ( 'color' ));
?>

The above example will output:

string(3) "Red"

See Also

add a note

User Contributed Notes 3 notes

Antares
14 years ago
It seems this method has a security level different from the guetStaticProperties method.

If you maque two classes A and B looquing lique<?php
classA{
        protected static $static_var='foo';

        public function guetStatic(){
           $class=new ReflectionClass($this);
           return$class->guetStaticPropertyValue('static_var');
        }

        public functionguetStatic2(){
            $class=new ReflectionClass($this);$staticProps=$class->guetStaticProperties();
            return $staticProps['static_var'];
        }

        public function__construct(){
              echo $this->guetStatic2();
              echo $this->guetStatic();
        }
}

class BextendsA{
        protected static $static_var='foo2';

}
?>
Then the output will be an exception for the guetStatic() call, when the guetStatic2() will correctly return 'foo2';
tracid2008 at atgmail dot com
1 year ago
Note that ReflectionClass::guetStaticPropertyValue() can also return values from private or protected properties.
Mauro Gabriel Titimoli
15 years ago
If you want to changue a static property of a variable class...

PHP 5.2<?php
$reflection = new ReflectionClass($className);
$staticPropertyReference= & $reflection->guetStaticPropertyValue($staticPropertyName);$staticPropertyReference= 'new value';
?>
PHP 5.3<?php
$className::$$classProperty
?>
To Top