8000 [PropertyInfo] Detection of primitive types is broken for classes with docblocks · Issue #46383 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content
[PropertyInfo] Detection of primitive types is broken for classes with docblocks #46383
Closed
@ostrolucky

Description

@ostrolucky

Symfony version(s) affected

6.1.0

Description

PropertyInfo incorrectly detects collection type for types not documented in docblock since 6.1 version. Deserialization then fails with error

In ArrayDenormalizer.php line 40:
                                                                     
  [Symfony\Component\Serializer\Exception\InvalidArgumentException]  
  Data expected to be an array, int given.                                                                        

This is because before, ConstructorExtractor has been called, but now this is no longer the case. Now, PhpstanExtractor is called, which resolves types documented in phpdoc only. I've checked a bit why is this the case and looks like on 6.0, this line is triggered

, while on 6.1 it isn't. But looks like real issue is that PhpStanExtractor is not returning null in getDocBlockFromProperty for such (non-documented) properties.

How to reproduce

deserialize

{"id": 1, "variations": []}

into

namespace Haushalt\Bl\DomainBundle\Domain\Product\Entity;

final class Product
{
    /**
     * @param \stdClass[]   $variations
     */
    public function __construct(
        public int $id,
        public array $variations,
    ) {
    }

    public function getId(): int
    {
        return $this->id;
    }
}

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

      0