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.
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();
...and have only one file ParentClass.php
(no separate files ChildClass1.php
or ChildClass2.php
).