Neos\Flow\Reflection\PropertyReflection::setValue PHP Méthode

setValue() public méthode

Returns the value of the reflected property - even if it is protected.
public setValue ( object $object = null, mixed $value = null ) : void
$object object Instance of the declaring class to set the value on
$value mixed The value to set on the property
Résultat void
    public function setValue($object = null, $value = null)
    {
        if (!is_object($object)) {
            throw new Exception('$object is of type ' . gettype($object) . ', instance of class ' . $this->class . ' expected.', 1210859212);
        }
        if ($this->isPublic()) {
            parent::setValue($object, $value);
        } else {
            parent::setAccessible(true);
            parent::setValue($object, $value);
        }
    }

Usage Example

 /**
  * @test
  */
 public function setValueEvenSetsValueOfAPublicProperty()
 {
     $reflectionProperty = new Reflection\PropertyReflection(__CLASS__, 'publicProperty');
     $reflectionProperty->setValue($this, 'modified');
     $this->assertEquals('modified', $this->publicProperty, 'ReflectionProperty->setValue() did not successfully set the value of a public property.');
 }