Clone¶
Clone makes a duplicate of an object.
PHP makes a shallow clone : it will only make a copy of the scalars properties, and it will keep the reference to any object untouched. This means that objects are shared between an object and its clone.
To perform a deep clone, aka to clone an object and its referenced properties, there is the magic method __clone().
<?php
class x { }
// instantiation
$x = new x;
// cloning
$y = clone $x;
?>
See also What happens when we clone?, Object Cloning, How to clone an object in PHP, PHP Clone All The Things
Related : Shallow Clone, Deep Clone
Added in PHP 4.0+