When cloning an object that is a child of another object, is it necessary to "specify" all the parent properties that are objects in the method of the child class __clone(), or can the method of the child class __clone()include only its own properties of the object that do not belong to the parent object?
Here is an example
The object Child_Aextends the object Parent_A.
An object Parent_Auses an object A_1in its constructor and has a method __clone().
class Parent_A{
function __construct(A_1 $a_1){
$this->A_1 = $a_1;
}
function __clone(){
$this->A_1 = clone $this->A_1;
}
}
An object Child_Ais required A_2.
class Child_A{
function __construct(A_2 $a_2){
parent::__construct(new A_1());
}
function __clone(){
$this->A_2 = clone $this->A_2;
}
}
If I want to make a deep copy Child_Athat will include deep_copy A_1, should be used in Child_A:
function __clone(){
$this->A_1 = clone $this->A_1;
$this->A_2 = clone $this->A_2;
}
, A_1:
function __clone(){
$this->A_2 = clone $this->A_2;
}
.