Trying to clone a stdClass
How to "clone" a php POSCO (Plain Old StdClass Object) via cast chaining:
$cloneObj = (object) (array) $myPOSCO;
var_dump($cloneObj == $myPOSCO); // true
var_dump($cloneObj === $myPOSCO); // false
When cloning an object, all the object properties are simply copied over to a new instance of the object. In effect this:
$cloned = new stdClass;
$cloned->date = $object->date;
As you probably know, assigning an object to another variable does not duplicate the object; there's still just one object, now with two references to it.
To deep-clone an object you need to implement a custom class with the __clone
method and manually clone
any child objects of it.