Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[PropertyInfo] Bug/BC break? - Getter return type seems to have higher priority than property type #38416

Closed
@rogamoore

Description

@rogamoore

Symfony version(s) affected: 5.1.6, 5.1.7

Description
Hello!

In one of our projects we have a class similar to this:

final class ExampleDTO{    private ?string $example;    public function __construct(?string $example)    {        $this->example = $example;    }    public function getExample(): string    {        return $this->example ?? 'fallback';    }}

It's used in the context of api platform, where incoming data is being deserialized to this object.

Before with Symfony 5.1.5 theexample property was detected as type?string, after upgrading to 5.1.6/5.1.7 it's only detected as typestring. Now when the incoming data contains a null value, it will fail withThe type of the "example" attribute must be "string", "NULL" given.

I did some tests and was able to track this new behaviour down to the property-info component. I suspect this change to be the reason:
#38041

It looks like now the return type ofgetExample() is used instead of the property type hint (?string).

So I would like to ask if this is the expected behaviour and if yes, how can I make the old way work again (somehow influence the priorities?). Thanks in advance!

How to reproduce
I created a reproducer here:
https://github.com/rogamoore/property-info-bug

Steps:

^ array:1 [▼  0 => Symfony\Component\PropertyInfo\Type {#116 ▼    -builtinType: "string"    -nullable: true    -class: null    -collection: false    -collectionKeyType: null    -collectionValueType: null  }]
^ array:1 [▼  0 => Symfony\Component\PropertyInfo\Type {#116 ▼    -builtinType: "string"    -nullable: false    -class: null    -collection: false    -collectionKeyType: null    -collectionValueType: null  }]

Additional context
PHP 7.4.10

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


      [8]ページ先頭

      ©2009-2025 Movatter.jp