-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
InvalidArgumentException - Unable to create a proxy for a final class #7598
Comments
No, you cannot: that's exactly what the exception says. |
my question was not precise, |
The ORM will need a proxy whenever a lazy association is to be built: this can happen also on collections and many-to-one. |
Should Doctrine forbid final classes for entities entirely, and throw an error during metadata loading ? This would help to spot this kind of errors earlier. |
@arnaud-lb feasible for 3.x, not for 2.x anymore, as we're pretty much closed for new features. |
I know it's and old closed topic, and I'm not sure doctrine can do something here. But from a domain perspective when you are using DDD and trying to move all the database mapping to the infrastructure layer, most likely to XML, you should not think about how to make a domain model to satisfy database/orm needs, and if some class from business domain perspective should never be extended it makes sense to set it as final. I remember a similar issue with PHPUnit mocking, which can be solved by Anyway, by the end of the day I like doctrine, you are doing a great job, but if the project you are working on is using the DDD paradigm I'm starting to think more and more about not using doctrine as it always leaks to the domain, and trying to tell you how you should write domain if you want to use doctrine. |
If you want to lazy-load an instance of such a class without the code that uses it being aware of the lazy-loading, you need a proxy that extends your class. And yes, that means it must not be final. If you want to document that a class must not have child classes however, you can still use the
A class loader that un-finals classes on the fly might be feasible for tests (still gives me the shivers though), but for production code, that's an absolute no-go. That being said, that loader requires no change from our side. If you want to fuck up your project with such a class loader, we cannot stop you.
No. If you want to have proxies of final classes, you need to build that feature into the PHP runtime itself. |
Doctrine unfortunately can't work with final or readonly classes. We are therefor forced to remove it from the entities. doctrine/orm#7598
Doctrine unfortunately can't work with final or readonly classes. We are therefor forced to remove it from the entities. doctrine/orm#7598
Doctrine unfortunately can't work with final or readonly classes. We are therefor forced to remove it from the entities. doctrine/orm#7598
… like that in certain situations. See doctrine/orm#7598
Support Question
I can't use final class?
InvalidArgumentException Unable to create a proxy for a final class "Mu\Domain\Model\Role\Role"
final class Role
final class User
The text was updated successfully, but these errors were encountered: