I have two classes named RA_Shortcode and WPBakeryShortCodesContainer
Now I need a third class RA_ShortcodeContainer inherit both classes..
Any idea how to achieve it.
Thanks in advance
I have two classes named RA_Shortcode and WPBakeryShortCodesContainer
Now I need a third class RA_ShortcodeContainer inherit both classes..
Any idea how to achieve it.
Thanks in advance
There is no current way to implement multiple inheritance with PHP. You can either use Traits to achieve what you are trying to accomplish or include the class(es) with require, include or use statements (or dependency injection). However, Traits seem like the best and most straight forward way to go.
The short answer is: you don't.
Based on your class names (btw, look up the concept of namespaces), there isn't even need for multiple inheritances.
When a class B
inherits from class A
, it means that class A
is a specialized case of B
.
Maybe this will illustrate your situation. Let's say you have a classes Box
and Cat
. And now you need a specialized BoxForCats
class. The BoxForCats
should never extend from Cat
. Instead you should apply compositions.
Your RA_ShortcodeContainer
class should just have:
public function addShortcode(RA_Shortcode $shortcode)
{
$this->list[] = $shortcode;
}
P.S. read up about LSP