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

Skip to content

[Serializer] Serializer stopped recognizing Types from @var in Constructor Parameters #60907

Closed as duplicate of#60795
@eXsio

Description

@eXsio

Symfony version(s) affected

7.3.0

Description

I'm migrating from Symfony 6.4 to 7.3 and my classes are not correctly deserializing after the upgrade due to the fact that I'm having my types hinted in @var PHPDoc segments instead of one single block with @param.

This doesn't work anymore (emails are deserialized into an array of plain PHP array s):


class ContactDto {

    public function __construct(
        /** @var ContactEmailDto[] */
        protected ?array  $emails = null,
    )
    {
    }
}

but it starts working once I change it to:


class ContactDto {

    /**
     * @param ContactEmailDto[]|null  $emails
     */
    public function __construct(
     
        protected ?array  $emails = null,
    )
    {
    }
}

I don't see any valid reason for dropping support of @var

How to reproduce

  1. Create a dummy class similar to

class ContactDto {

    public function __construct(
        /** @var ContactEmailDto[] */
        protected ?array  $emails = null,
    )
    {
    }
}

  1. Try to deserialize it and see that the emails were deserialized into an array of plain PHP arrays instead of instances of ContactEmailDto

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