Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Serializer] Call to undefined function is_false() #57334

Closed as not planned
Closed as not planned
@Prometee

Description

@Prometee

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions