Translations:Developers/Object oriented programming in PHP/Objects/10/en

With clone all properties of the cloned object are copied to the new object. Properties containing scalar types or arrays are just copied when assigned, but if the properties of the cloned object contain identifiers to objects itself, then only these identifiers are copied. This results in two different objects with properties pointing to the same objects. To circumvent this behaviour and actually copy the objects hold by the properties of the cloned object, the magic __clone method must be implemented in the class definition of the cloned object. In this __clone method the objects referenced in its properties can be cloned by using the clone keyword again: