When I clone an istance of System class I want to clone all SubSystem istances in $subsystems array too, so I tryed with this code
class System {
public $name;
public $subsystems = array();
function __construct($name){
$this->name = $name;
}
function __clone(){
foreach( $this->subsystems as $key => $item ){
$this->subsystems[$key] = clone($this->subsystems[$key]);
}
}
}
class SubSystem {
public $name;
public $type = 2;
public $skip_AP_search = false;
function __construct($name){
$this->name = $name;
}
}
But when I clone...
--- var_dump($orig->subsystems);
array(1) {
[0]=>
&object(SubSystem)#12 (7) {
["name"]=>
string(4) "sub1"
["type"]=>
int(2)
["skip_AP_search"]=>
bool(false)
}
}
--- var_dump($copy->subsystems);
array(1) {
[0]=>
&object(SubSystem)#12 (7) {
["name"]=>
string(4) "sub1"
["type"]=>
int(2)
["skip_AP_search"]=>
bool(false)
}
}
So the istances in the arrays are the same 🙁
What's wrong?