BetterReflection\Reflection\ReflectionClass::setStaticPropertyValue PHP Method

setStaticPropertyValue() public method

Set the value of a static property
public setStaticPropertyValue ( string $propertyName, mixed $value ) : void
$propertyName string
$value mixed
return void
    public function setStaticPropertyValue($propertyName, $value)
    {
        if (!class_exists($this->getName(), false)) {
            throw new Exception\ClassDoesNotExist('Property cannot be set as the class is not loaded');
        }
        if (!$this->hasProperty($propertyName) || !$this->getProperty($propertyName)->isStatic()) {
            throw new Exception\PropertyDoesNotExist('Property does not exist on class or is not static');
        }
        // PHP behaviour is to simply say "property does not exist" if accessing
        // protected or private values. Here we be a little more explicit in
        // reasoning...
        if (!$this->getProperty($propertyName)->isPublic()) {
            throw new Exception\PropertyNotPublic('Property is not public');
        }
        $className = $this->getName();
        $className::${$propertyName} = $value;
    }