Skip to content

[PropertyInfo] PhpStanTypeHelper doesn't support ConstTypeNode #44491

@ostrolucky

Description

@ostrolucky

Description

After updating from Symfony 5.3 to Symfony 5.4, our code started to crash. This is because new PhpStanExtractor was introduced that was prioritized above older extractors. This extractor started to return null type and hence serializer failed to denormalize our objects.

It returns null, because this is a UnionTypeNode containing ConstTypeNode and IdentifierTypeNode (null). However PhpStanTypeHelper doesn't handle ConstTypeNode and hence symfony/property-info will return null only.

Example

class Foo
{
   /**
     * @return PageType::*|null
     */
    public function getDynamicPageType(): ?string
    {
        return rand(0, 1) ? PageType::FOO : null;
    }
}

class PageType {
    const FOO = 'foo';
}

On Symfony 5.3, this returns string|null. On Symfony 5.4, because PhpStanExtractor was added which doesn't correctly handle unions, it returns null.

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