Is something like the following possible in PHP?
$blah = 'foo1';
class foo2 extends $blah {
//...
}
class foo1 {
//...
}
This gives an error.
I want to dynamically set $blah so I can extend whatever class I want.
Edit: The reason for wanting to do this because I wanted to use a function out of another class in a related class. In the end it would have been something like:
Final extends foo1 extends foo2 extends foo3 extends foo4 extends parent { ... }
In the end I decided to instantiate the other class within the class and use it. Not the best options because they both you 2 of the same classes, but this won't be used that often, so it will work for now.
I know this question was asked a long time ago, but the answer is relatively simple.
Assuming you want to extend class foo if class foo exists, or class bar if it doesn't, you'd use:
I assume that this is for ease-of-maintenance, right? Extending a class at run time really is pretty crazy.
Then, when you want to change all your
DescendantClass*
classes, you just have to change what the IntermediateClass extends: