diff --git a/src/Metadata/Driver/TypedPropertiesDriver.php b/src/Metadata/Driver/TypedPropertiesDriver.php index 4d8c4ee5d..15c4f9d67 100644 --- a/src/Metadata/Driver/TypedPropertiesDriver.php +++ b/src/Metadata/Driver/TypedPropertiesDriver.php @@ -113,7 +113,14 @@ public function loadMetadataForClass(ReflectionClass $class): ?ClassMetadata } elseif ($this->shouldTypeHintUnion($reflectionType)) { $propertyMetadata->setType([ 'name' => 'union', - 'params' => [$this->reorderTypes(array_map(fn (string $type) => $this->typeParser->parse($type), $reflectionType->getTypes()))], + 'params' => [ + $this->reorderTypes( + array_map( + fn (string $type) => $this->typeParser->parse($type), + array_filter($reflectionType->getTypes(), [$this, 'shouldTypeHint']), + ), + ), + ], ]); } } catch (ReflectionException $e) { diff --git a/tests/Fixtures/TypedProperties/UnionTypedProperties.php b/tests/Fixtures/TypedProperties/UnionTypedProperties.php index 86ab59b6e..d7f40dde2 100644 --- a/tests/Fixtures/TypedProperties/UnionTypedProperties.php +++ b/tests/Fixtures/TypedProperties/UnionTypedProperties.php @@ -8,6 +8,8 @@ class UnionTypedProperties { private int|bool|float|string $data; + private int|bool|float|string|null $nullableData; + public function __construct($data) { $this->data = $data;