So that the final class have all member variables/methods in both class
Is there an easy way to go?
You should encapsulate the both classes in a containing class, and provide a relevant interface (such as setters/getters for private variables
class YourFirstClass {
public $variable;
private $_variable2;
public function setVariable2($a) {
$this->_variable2 = $a;
}
}
class YourSecondClass {
public $variable;
private $_variable2;
public function setVariable2($a) {
$this->_variable2 = $a;
}
}
class ContaingClass {
private $_first;
private $_second;
public function __construct(YourFirstClass $first, YourSecondClass $second) {
$this->_first = $first;
$this->_second = $second;
}
public function doSomething($aa) {
$this->_first->setVariable2($aa);
}
}
Research (google): "composition over inheritance"
Footnote: sorry for non-creative variable names..
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With