ReflectionClass::setStaticPropertyValue

(PHP 5 >= 5.1.0)

ReflectionClass::setStaticPropertyValueSets static property value

Description

public void ReflectionClass::setStaticPropertyValue ( string $name , string $value )

Sets static property value.

Warning

This function is currently not documented; only its argument list is available.

Parameters

name

Property name.

value

New property value.

Return Values

No value is returned.

See Also

Коментарии

It is important to note that calling ReflectionClass::setStaticPropertyValue will not allow you to add new static properties to a class.
2012-07-13 16:40:04
http://php5.kiev.ua/manual/ru/reflectionclass.setstaticpropertyvalue.html
Автор:
Calling this method on a static property that is not public will return a ReflectionException stating the property does not exist. This is quite misleading as the property is valid.

class test {
    public static $publicProperty = 'public';
    private static $privateProperty = 'private';

    public static function printProperties() {
        echo self::$publicProperty . "\n";
        echo self::$privateProperty . "\n";
    }


$reflectedClass = new \ReflectionClass('test');
$reflectedClass->setStaticPropertyValue('publicProperty', 'foo');
$reflectedClass->setStaticPropertyValue( 'privateProperty', 'bar' );

PHP Fatal error:  Uncaught exception 'ReflectionException' with message 'Class test does not have a property named privateProperty'

If you retrieve the method using the reflection class getProperty method you can circumnavigate this issue

$reflectedProperty = $reflectedClass->getProperty('privateProperty');
$reflectedProperty->setAccessible(true);
$reflectedProperty = $reflectedProperty->setValue('bar');

test::printProperties(); 
will echo
foo
bar
2014-04-01 01:53:28
http://php5.kiev.ua/manual/ru/reflectionclass.setstaticpropertyvalue.html

    Поддержать сайт на родительском проекте КГБ