Can't use readonly class because of doctrine proxies #7504

Open
opened 2026-01-22 15:52:29 +01:00 by admin · 2 comments
Owner

Originally created by @vincent-philippe on GitHub (May 12, 2025).

Bug Report

Q A
Version doctrine/orm 3.3.2
Version php 8.2

Summary

I've got a blocking issue while trying to use a class which is a readonly class.

I just can't use it since doctrine has auto-generated a Proxy for this class which is not readonly.

That's because the PROXY_CLASS_TEMPLATE does not manage readonly class.

Current behavior

Error ⚠

  Compile Error: Non-readonly class Proxies\__CG__\App\Entity\FilteringQuestion cannot extend readonly class App\Entity\FilteringQuestion  

Generated proxy is such as :

namespace Proxies\__CG__\App\Entity;

/**
 * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
 */
class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy
{
...

Expected behavior

No error ✔

Generated proxy is such as :

namespace Proxies\__CG__\App\Entity;

/**
 * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR
 */
readonly class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy
{
...

How to reproduce

In Symfony environment it's possible to define a configuration (in dev only) to auto generate proxy class.

To generate the proxy, check the doctrine.orm.auto_generate_proxy_classes: true.

You can reproduce the issue easyli create a class such as :

#[ORM\Entity()]
readonly class FilteringQuestion {...}

The generated proxy will be

class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy {...}
Originally created by @vincent-philippe on GitHub (May 12, 2025). ### Bug Report | Q | A |-------------------------------------------- | ------ | Version doctrine/orm | 3.3.2 | Version php | 8.2 #### Summary I've got a blocking issue while trying to use a class which is a readonly class. I just can't use it since doctrine has auto-generated a Proxy for this class which is not readonly. That's because the [PROXY_CLASS_TEMPLATE](https://github.com/doctrine/orm/blob/1f1891d3e20ef9881e81c2f32c53e9dc88dfc9a7/src/Proxy/ProxyFactory.php#L93) does not manage readonly class. #### Current behavior Error ⚠ ```sh Compile Error: Non-readonly class Proxies\__CG__\App\Entity\FilteringQuestion cannot extend readonly class App\Entity\FilteringQuestion ``` Generated proxy is such as : ```php namespace Proxies\__CG__\App\Entity; /** * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR */ class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy { ... ``` #### Expected behavior No error ✔ Generated proxy is such as : ```php namespace Proxies\__CG__\App\Entity; /** * DO NOT EDIT THIS FILE - IT WAS CREATED BY DOCTRINE'S PROXY GENERATOR */ readonly class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy { ... ``` #### How to reproduce In Symfony environment it's possible to define a configuration (in dev only) to auto generate proxy class. To generate the proxy, check the `doctrine.orm.auto_generate_proxy_classes: true`. You can reproduce the issue easyli create a class such as : ```php #[ORM\Entity()] readonly class FilteringQuestion {...} ``` The generated proxy will be ```php class FilteringQuestion extends \App\Entity\FilteringQuestion implements \Doctrine\ORM\Proxy\InternalProxy {...} ```
Author
Owner

@vincent-philippe commented on GitHub (May 19, 2025):

up !

maybe there's a workaround ?

@vincent-philippe commented on GitHub (May 19, 2025): up ! maybe there's a workaround ?
Author
Owner

@vincent-philippe commented on GitHub (May 22, 2025):

up !

maybe there's a workaround ?

@vincent-philippe commented on GitHub (May 22, 2025): up ! maybe there's a workaround ?
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#7504