In PHP objects are automatically passed by reference:
$obj1 = new stdClass();
$obj1->foo = 'bar';
$obj2 = $obj1;
$obj2->foo = 'OOF';
var_dump($obj1->foo); // OOF
You can clone the object:
$obj2 = clone $obj1;
$obj2 will be a shallow copy of
$obj1. As stated in the PHP manual:
When an object is cloned, PHP 5 will perform a shallow copy of all of the object's properties. Any properties that are references to other variables will remain references.
You can override the
__clone() method to manually clone any subobjects if you wish.