How to masquerade child classes in parent class with autoloading (php)

aginza

New Member
I have a base class that is inherited by about ten subclasses. Most of these subclasses have very similar behavior, but I want to define specialized methods only for three of them.Is it possible to masquerade the existence of these classes, by autoloading the parent class every time an object of the child class is instantiated? This way I would not have to define multiple classes with the same code?E.g.\[code\]class ParentClass { public function __construct() { switch(get_class($this)) { case "ChildClass1" : do_stuff() break; case "ChildClass2" : do_other_stuff() break; default: break; } }}$c1 = new ChildClass1();$c2 = new ChildClass2();\[/code\]...and have only one file \[code\]ParentClass.php\[/code\] (no separate files \[code\]ChildClass1.php\[/code\] or \[code\]ChildClass2.php\[/code\]).
 
Back
Top