Closed
Description
Symfony version(s) affected
5.4+
Description
Using ReflectionExtractor::getType on a property typed with ?array
and an adder typed with an object incorrectly returns the type as non nullable.
This issue can lead to problems using symfony/serializer during denormalization for example, causing it to fail since the denormalizer expect the fetched type from the ReflectionExtractor to be non-nullable even when given property is properly declared as such
How to reproduce
An example using a Video
class with an array of Comment
class on a $comments
property (phpDoc is only indicative here for clarity purposes)
class Video
{
public ?string $title = null;
/**
* @var Comment[]|null
*/
public array|null $comments;
private function setTitle(?string $title): void
{
$this->title = $title;
}
private function addComment(Comment $comment): void
{
$this->comments[] = $comment;
}
}
class Comment
{
public string $content;
}
$extractor = new ReflectionExtractor();
$property = $extractor->getType(Video::class, 'comments');
$property->isNullable();
// returns false
Practical example with Xdebug :
Possible Solution
Additional Context
No response