Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wrong typehint for DateTime #1

Open
klkvsk opened this issue Feb 6, 2024 · 1 comment
Open

Wrong typehint for DateTime #1

klkvsk opened this issue Feb 6, 2024 · 1 comment

Comments

@klkvsk
Copy link

klkvsk commented Feb 6, 2024

Given the following property

    #[ORM\Column(type: 'datetimetz_immutable', nullable: false)]
    protected ?DateTimeInterface $date;

generated output will be:

    public function setDate(?\DateTimeImmutable $date): self
    {
        $this->date = $date;

        return $this;
    }

    public function getDate(): ?\DateTimeImmutable
    {
        return $this->date;
    }

(note that typehint is \DateTimeImmutable, not \DateTimeInterface)

While this is technically correct from Doctrine's point of view, it will be better to prefer interface as typehint, especially when it is explicitly used in property's type.

@hlecorche
Copy link
Contributor

I'm currently working on the development of version 2.1, which will include the functionality to utilize PHP property types for getters/setters, including both the PHP property type and whether the property can be nullable. This will become the default behavior in version 3.0.

I will update this ticket once this feature becomes available.

In the meantime, if you wish to modify this behavior, you can override the Twig template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants