1
I have a class:
class Children extends Database
Soon, Children
is the daughter class and Database
the parent class, in the parent class I have the attribute:
protected $object = null;
The value of it must 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 straight I forget to put the line $this->object = $this;
in the manufacturer, and this affects the functioning.
If I put $this->object = $this;
in the Database class constructor will not work because it will store the instance Database
attribute, not the class instance Children
.
There’s a way in the father class builder I set that attribute worth your son?
For when I give one new Children()
the attribute object
class Database
Already worth that instance, taking away the need to have the $this->object = $this;
in the builder of the daughter class (Children
).
In doing new Children()
the goal would be:
// Construtor da classe Database
public function __construct()
{
$this->object = instancia criada de Children
}
I didn’t understand the last paragraph, when creating a
Children
you want that somehow it changes the state ofDatabase
?– rray
That’s more or less what it would be like to create a
Children
want to store instance of it in class attributeDatabase
. The difficulty is to indicate the child class in theDatabase
. The attributeobject
should store the child class instance, which in this case isChildren
. In short, it would be to do the same as$this->object = $this
, only in the parent class (Database)– Leonardo