Some may argue that this may be bad practice due to potential inconsistencies, but I wonder how (if possible) I could tell the class about extending another class, but only if it is defined.
I know that this will not work, but what I do is:
class MyClass extends (class_exists('OtherClass') ? OtherClass : null)
Or maybe a function that will work in the constructor to install the extension, if the class exists.
Of course, I want to avoid.
if(class_exists('OtherClass')) { class MyClass extends OtherClass {
.. due to massive code duplication.
I searched the answers on Google and around the site, but didnโt find anything - if I repeated the question, let me know.
source share