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

getValue() public méthode

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

Usage Example

 /**
  * @test
  */
 public function getValueReturnsValueOfAPrivatePropertyEvenIfItIsAnObject()
 {
     $reflectionProperty = new Reflection\PropertyReflection(__CLASS__, 'privateProperty');
     $this->protectedProperty = new \ArrayObject(['1', '2', '3']);
     $this->assertEquals($this->privateProperty, $reflectionProperty->getValue($this), 'ReflectionProperty->getValue($this) did not return the object of our private property.');
     $this->privateProperty = $this;
     $this->assertSame($this, $reflectionProperty->getValue($this), 'ReflectionProperty->getValue($this) did not return the reference to $this.');
 }
All Usage Examples Of Neos\Flow\Reflection\PropertyReflection::getValue