diff --git a/Mapping/PropertyMetadata.php b/Mapping/PropertyMetadata.php index 74ecf02cf..2a8d3f4f5 100644 --- a/Mapping/PropertyMetadata.php +++ b/Mapping/PropertyMetadata.php @@ -48,7 +48,13 @@ public function __construct(string $class, string $name) */ public function getPropertyValue($object) { - return $this->getReflectionMember($object)->getValue($object); + $reflProperty = $this->getReflectionMember($object); + + if (\PHP_VERSION_ID >= 70400 && !$reflProperty->isInitialized($object)) { + return null; + } + + return $reflProperty->getValue($object); } /** diff --git a/Tests/Fixtures/Entity_74.php b/Tests/Fixtures/Entity_74.php new file mode 100644 index 000000000..cb22fb7f7 --- /dev/null +++ b/Tests/Fixtures/Entity_74.php @@ -0,0 +1,8 @@ +expectException('Symfony\Component\Validator\Exception\ValidatorException'); $metadata->getPropertyValue($entity); } + + /** + * @requires PHP 7.4 + */ + public function testGetPropertyValueFromUninitializedProperty() + { + $entity = new Entity_74(); + $metadata = new PropertyMetadata(self::CLASSNAME_74, 'uninitialized'); + + $this->assertNull($metadata->getPropertyValue($entity)); + } }