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

Appearance settings

[Serializer] Incorrectly uses static method as getters #59916

Copy link
Copy link
Open
@BoShurik

Description

@BoShurik
Issue body actions

Symfony version(s) affected

7.2.1

Description

If an object have static methods with same name as a property they are used to get value of this properties

How to reproduce

#[AsCommand(name: 'app:issue', description: 'Serialization issue')]
class IssueCommand extends Command
{
    public function __construct(private readonly SerializerInterface $serializer)
    {
        parent::__construct();
    }

    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $foo = new Foo('id');

        $output->writeln($this->serializer->serialize($foo, 'json'));

        return Command::SUCCESS;
    }
}

final readonly class Foo
{
    public static function id(string $id): self
    {
        return new self($id);
    }

    public function __construct(public ?string $id = null)
    {
    }
}

Got Too few arguments to function App\Command\Foo::id(), 0 passed

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

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.