Cloning objects that contain objects
<p>Because PHP passes objects by reference by default I've run into a little problem that the follow script demos:</p>

<pre><code>$a = new stdClass();
$a-&gt;b = new stdClass();
$a-&gt;b-&gt;c = 1;

$d = clone $a;

$a-&gt;b-&gt;c = 10;

print_r($a);
print_r($d);
</code></pre>

<p>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.</p>
