I have two classes:
abstract Entity, abstract ClassA extends Entity, ClassB extends ClassA
Entity is an generic class for all kinds of entities, such as Cars or Students. There is an static class variable called $_entity_name
, which contains the exact class name of the entity in the ER diagram.
The big problem: Entity can't set the value of this variable, but uses it! So I must define it in Entity, but I can't redefine it in ClassA.
ClassA is the auto-generated base class of an special ORM entity (lets say "Student"). The user is supposed to subclass this base class to add his own business logic.
ClassB is created by the user and extends ClassA. That's the place where he adds his business logic. He's not supposed to touch $_entity_name
or set this value.
The only way I see is this:
ClassA defines an init() method which initializes these "system level" instance variables to reasonable values.
I want the user to not have to think at all about calling anything which is unusual. I don't know if it's usual in PHP to explicitely also call the constructor of the parent class, or not. But I guess it isn't.
Questions: A) What's the most convenient way to call init() after instantiation of the class? B) Is there a way to achieve that in such a way, that the user who creates ClassB must not think at all about calling init()? C) What other options do I have?