phpstan-doctrine
phpstan-doctrine copied to clipboard
Implement a rule that prevents final constructors in Doctrine Entities
Hello there,
I'm having quite a hard time getting my head around this : final methods in Doctrine Entities. There's a PR that added a check that Entities cannot be final (the class itself), but a comment from the author said he doesn't want to add checks for final methods.
However, from what I can see in my Doctrine proxied classes in var/cache in production, all methods of the class is inherited/overridden in proxies. So it just cannot work with a final method, whichever it is.
Why hasn't this check been added then ?
I'm curious about your insights. Thanks! gnutix
Ask the author :) /cc @enumag
Yeah I have a case where I don't want the proxy to override my method because that would in fact cause a bug for me. Granted it's a bit of an edge-case so adding such rule to PHPStan makes sense but please make it separate from the rule I added so that I can disable it in my app.
@enumag But how could it even work in your app ? When I added final to a private constructor of an entity, PHP just broke saying "cannot override final method" (in the Doctrine Proxy). How can you have a final method in an entity then, and not having Doctrine's proxy to break ? :thinking:
There is a misunderstanding... the method is not the constructor. When there is a final non-constructor method, Doctrine simply skips it.
Okay, so you agree that there should be a rule (that is always loaded) guarding against final constructors for Doctrine Entities (not all methods) then ?
Sure.
This thread has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.