Because PHP passes objects by reference by default I’ve run into a little problem that the follow script demos:
$a = new stdClass();
$a->b = new stdClass();
$a->b->c = 1;
$d = clone $a;
$a->b->c = 10;
print_r($a);
print_r($d);
Is there a way to clone a stdClass and also clone any objects that it might contain? I understand I can use the __clone method to prevent this behavior, but my object is being built via json_decode.
I believe the accepted way is to serialize and unserialize the composite object