I have a class:
class Children extends Database
So, Children
is the child class and Database
the parent class, in the parent class I have the attribute:
protected $object = null;
The value of it should be the instance of the child class, currently to set this attribute I am using:
// Construtor da classe Children
public function __construct($id = null, $daddy = null, $people = null)
{
$this->id = $id;
$this->daddy = $daddy ;
$this->people = $people;
$this->object = $this;
}
But straightforward I forget to put the line $this->object = $this;
in the constructor, and this affects the operation.
If I put $this->object = $this;
in the constructor of the Database class it will not work because it will store the Database
instance in the attribute, not the instance of the Children
class.
Is there a way in the parent class constructor to set this attribute for your child?
For when I give a new Children()
the attribute object
of class Database
It is already worth this instance, making it necessary to have $this->object = $this;
in the constructor of the child class ( Children
).
When doing new Children()
the goal would be:
// Construtor da classe Database
public function __construct()
{
$this->object = instancia criada de Children
}