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

Public readonly properties are unset in Proxy's constructor #954

Open
solcik opened this issue Jan 27, 2022 · 0 comments · May be fixed by #957 or #999
Open

Public readonly properties are unset in Proxy's constructor #954

solcik opened this issue Jan 27, 2022 · 0 comments · May be fixed by #957 or #999

Comments

@solcik
Copy link
Sponsor

solcik commented Jan 27, 2022

Failing Test

Q A
BC Break no
Version 3.2.0

Summary

Public readonly properties are unset in Proxy's constructor, which results in error.

Current behavior

Cannot unset readonly property \Entity\SimpleBook::$title from scope Proxies\__CG__\Entity\SimpleBook

How to reproduce

#[Entity, Table]
class SimpleBook
{
    #[Column, Id, GeneratedValue]
    private readonly int $id;

    #[Column]
    public readonly string $title;

    #[ManyToOne, JoinColumn(nullable: false)]
    private readonly Author $author;

    public function getId(): int
    {
        return $this->id;
    }

    public function getTitle(): string
    {
        return $this->title;
    }

    public function getAuthor(): Author
    {
        return $this->author;
    }
}

class SimpleBook extends \Entity\SimpleBook implements \Doctrine\ORM\Proxy\Proxy
{
    // ...

    public function __construct(?\Closure $initializer = null, ?\Closure $cloner = null)
    {
        unset($this->title);

        $this->__initializer__ = $initializer;
        $this->__cloner__      = $cloner;
    }
}

Expected behavior

Code that generates Proxy's constructor

I dug into ProxyGenerator and here is generation of these unsets:

public readonly properties are not tested as I see in tests.

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