Closed as not planned
Description
Symfony version(s) affected
7.1.0
Description
I found an issue on symfony/serializer
. I was trying to denormalize an array
into an object
which have an id
property with types int|null|false
.
The error displayed is :
Error: Call to undefined function is_false()
vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:780
vendor/symfony/serializer/Normalizer/AbstractObjectNormalizer.php:380
(I also have the same error for mixed type: “Call to undefined function is_mixed()“)
Here is the test to reproduce it:
<?php
use Symfony\Component\Serializer\Tests\Php80Dummy;
public function testDenormalizeFalsePseudoTypeButSetAString(): void
{
// given a serializer that extracts the attribute types of an object via ReflectionExtractor
$propertyTypeExtractor = new PropertyInfoExtractor([], [new ReflectionExtractor()], [], [], []);
$objectNormalizer = new ObjectNormalizer(null, null, null, $propertyTypeExtractor);
$serializer = new Serializer([$objectNormalizer]);
// when denormalizing some data into an object where an attribute uses the false pseudo type
/** @var Php80Dummy $object */
$object = $serializer->denormalize(['canBeFalseOrString' => 'aString'], Php80Dummy::class);
// then the attribute that declared false was filled correctly
$this->assertEquals('aString', $object->canBeFalseOrString);
}
I simply changed the array value from false to 'aString' in this existing PHPUnit test :
https://github.com/symfony/symfony/blob/7.1/src/Symfony/Component/Serializer/Tests/Normalizer/ObjectNormalizerTest.php#L768-L782
How to reproduce
<?php
use Symfony\Component\Serializer\Tests\Php80Dummy;
public function testDenormalizeFalsePseudoTypeButSetAString(): void
{
// given a serializer that extracts the attribute types of an object via ReflectionExtractor
$propertyTypeExtractor = new PropertyInfoExtractor([], [new ReflectionExtractor()], [], [], []);
$objectNormalizer = new ObjectNormalizer(null, null, null, $propertyTypeExtractor);
$serializer = new Serializer([$objectNormalizer]);
// when denormalizing some data into an object where an attribute uses the false pseudo type
/** @var Php80Dummy $object */
$object = $serializer->denormalize(['canBeFalseOrString' => 'aString'], Php80Dummy::class);
// then the attribute that declared false was filled correctly
$this->assertEquals('aString', $object->canBeFalseOrString);
}
Possible Solution
No response
Additional Context
No response