Public readonly properties are unset in Proxy's constructor
- Dominant language
- PHP
- Stars
- 5.8k
- Forks
- 284
- PR merge metrics
- No merged PRs in 30d
Description
### Failing Test
| Q | A
|------------ | ------
| BC Break | no
| Version | 3.2.0
- https://github.com/doctrine/orm/issues/9432
- https://github.com/doctrine/orm/pull/9431
#### 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
```php
#[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:
- https://github.com/doctrine/common/blob/3.2.x/lib/Doctrine/Common/Proxy/ProxyGenerator.php#L979
`public readonly ` properties are not tested as I see in tests.
- https://github.com/doctrine/common/blob/3.2.x/tests/Doctrine/Tests/Common/Proxy/ProxyGeneratorTest.php#L481
Contributor guide
Assessment
This issue has not been assessed yet.