I want to add some data form child class to parent class using the same method and also want to retrieve the data. Please check the example code that will help you for better understanding.
class HTML{
public function add_control(){
}
public function all_controls(){
}
}
class Control1 extends HTML
{
public function register_controls()
{
$this->add_control([
'name' => 'a',
'label' => 'A',
]);
$this->add_control([
'name' => 'b',
'lable' => 'B',
]);
}
}
class Control2 extends HTML{
public function register_controls()
{
$this->add_control([
'name' => 'c',
'label' => 'C',
]);
}
}
(new HTML)->all_controls();
Sample Output ['a','b','c'] I hope you got my point.
HTMLclass, which is what it looks like you want, it doesn't have any knowledge ofControl1orControl2instances (or even that those subclasses exist). You might want to look at something like the Composite Pattern