Trying to simplify my entities. Doctrine entities. I have few SupperClasses in the system, so I was thinking "hey, php 8 attributes are language feature maybe it can be used and super class removed totally?". I see doctrine supports attributes.
So can doctrine entities be inherited if written with attributes instead of annotation and can php 8 attributes be inherited in classes that are not doctrine entities?
CodePudding user response:
As of the latest stable Doctrine (Sept 2022), no. It requires the attributes to be present on each class you're actually using (even if it inherits a class that has the attributes expected).
In fact, some attributes, like not providing an Entity
attribute on a subclass of a class that does, will still cause an Exception
to be thrown.
It seems like something that could be added to Doctrine by having it traverse up the class tree and overwrite defaults with whatever attributes are found, but it doesn't currently do that. There are likely a number of reasons for it not being implemented (attributes only more recently being added, code complexity, performance, deciding what would get overwritten, etc).