Skip to content

[ObjectMapper] Allow constructor to be called when there are no mapped constructor parameters. #60797

Closed
@anthonylex

Description

@anthonylex

Description

A constructor is not called when there are no constructor arguments.
However there are cases where you would want it to be able to be called such as mapping to a doctrine entity that has a collection so the collection is initialised:

class Article
{
    #[ORM\ManyToMany(targetEntity: Tag::class, cascade: ['persist'])]
    private Collection $tags;

    public function __construct()
    {
        $this->tags = new ArrayCollection();
    }
}

It results in this error:

<!-- The property App\Entity\Article::$tags is not readable because it is typed Doctrine\Common\Collections\Collection. You should initialize it or declare a default value instead. (500 Internal Server Error) -->

Example

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

      pFad - Phonifier reborn

      Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

      Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


      Alternative Proxies:

      Alternative Proxy

      pFad Proxy

      pFad v3 Proxy

      pFad v4 Proxy