Skip to content

[Serializer] Call to undefined function is_mixed() in AbstractObjectNormalizer.php line 780 #57314

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
faizanakram99 opened this issue Jun 4, 2024 · 3 comments

Comments

@faizanakram99
Copy link
Contributor

Symfony version(s) affected

7.1.1

Description

#53160 introduced a bug in serializing objects with mixed type.

How to reproduce

Serialize any object with at least one property with mixed type.

Possible Solution

No response

Additional Context

No response

@HypeMC
Copy link
Contributor

HypeMC commented Jun 4, 2024

I can't seem to reproduce this error. I tried the following:

class Test
{
    public function __construct(
        public mixed $test,
    ) {
    }
}

and

class Test
{
    public function __construct(
        private mixed $test,
    ) {
    }

    public function getTest(): mixed
    {
        return $this->test;
    }
}

Could you create a reproducer?

@xabbuh
Copy link
Member

xabbuh commented Jun 5, 2024

I wasn't able to come up with a test case, but reading the existing code #57320 should fix the reported issue.

@BooleanType
Copy link

I have the same error since I've upgraded to 7.1.1.

$userAvatarDto = $serializer->deserialize(
    $content,
    UserAvatarDto::class,
    'json'
);

... where:

  • $content is some string; when $content is {"avatar":null}, error disappears:
{"avatar":"data:image\/jpeg;base64,\/9j\/4AAQSkZJRgABAgAAAQABAAD\/2wBDAAIBAQIBAQICAgICAgICAwUDAwMDAwYEBAMFBwYHBwcGBwcICQsJCAgKCAcHCg0KCgsMDAwMBwkODw0MDgsMDAz\/2wBDAQICAgMDAwYDAwYMCAcIDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAz\/wgARCAK6BNgDASIAAhEBAxEB\/8QAHQAAAQUBAQEBAAAAAAAAAAAAAAECBAUGAwcICf\/EABoBAAIDAQEAAAAAAAAAAAAAAAABAgME"}
  • UserAvatarDto:
class UserAvatarDto
{
    #[Assert\Sequentially([
        new Assert\NotBlank(
            allowNull: true,
            message: HttpErrorMessage::USER_EDITION_AVATAR_MISSING->value,
            normalizer: 'trim'
        ),
        new Assert\Type('string', message: HttpErrorMessage::USER_EDITION_AVATAR_WRONG_FORMAT->value),
    ])]
    private mixed $avatar = null;

    /**
     * Get the value of avatar.
     */
    public function getAvatar(): mixed
    {
        return $this->avatar;
    }

    /**
     * Set the value of avatar.
     */
    public function setAvatar(mixed $avatar): self
    {
        $this->avatar = $avatar;

        return $this;
    }
}

xabbuh added a commit that referenced this issue Jun 6, 2024
…ions (xabbuh)

This PR was merged into the 7.1 branch.

Discussion
----------

[Serializer] avoid calling undefined built-in is_*() functions

| Q             | A
| ------------- | ---
| Branch?       | 7.1
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Issues        | Fix #57314
| License       | MIT

Commits
-------

e0a6587 avoid calling undefined built-in is_*() functions
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

7 participants