Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Prometee opened this issue Jun 6, 2024 · 2 comments
Closed

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

Prometee opened this issue Jun 6, 2024 · 2 comments

Comments

@Prometee
Copy link

Prometee commented Jun 6, 2024

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

@derrabus
Copy link
Member

derrabus commented Jun 6, 2024

Duplicate of #57314.

@derrabus derrabus closed this as not planned Won't fix, can't repro, duplicate, stale Jun 6, 2024
@Prometee
Copy link
Author

Prometee commented Jun 6, 2024

This PR #57320 fixed both issues with is_false() and is_mixed().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants