How can I create child objects from within the parent?
class Section
{
protected $url;
function __construct($url)
{
$this->url = $url;
}
public function createElements()
{
}
}
class ElementA extends Section
{
}
class ElementB extends Section
{
}
Each section will contain multiple elements, however, the whole purpose of the section class, is to create the elements, not just store data relating to the section.
You could do it just like this:
public function createElements()
{
$this->children[] = new ElementA($this->url); // use $this->url
$this->children[] = new ElementB('http://www.google.com'); // or not
}