An object copy is created by using the clone keyword (which calls the object’s __clone() method if possible). An object’s __clone() method cannot be called directly. When an object is cloned, PHP will perform a shallow copy of all of the object’s properties. Any properties that are references to other variables will remain references.
$copy_object_name = clone $object_to_be_copied
Program 1: Program to create copy of an object.
GeeksforGeeks Computer science portal
Example 2: Below program distinguishes clone from assignment ( = ) operator.
GeeksforGeeks Python for Machine learning GeeksforGeeks
Note: It is clear that cloned object have different values than original object but original and refrenced object created by using ‘=’ operator have same value.
- How to create a shallow copy of SortedList Object in C#
- How to copy a DateTime object in PHP ?
- How to create a shallow copy of Hashtable in C#
- C# | How to create a shallow copy of the BitArray
- Different ways to create an Object in C#
- Shallow Copy and Deep Copy in C#
- PHP | Type Casting and Conversion of an Object to an Object of other class
- How to select first object in object in AngularJS?
- HTML | DOM Object Object
- PHP | Ds\Set copy() Function
- PHP | copy( ) Function
- PHP Ds\Map copy() Function
- How to copy a map to another map in Golang?
- How to copy the content of a div into another div using jQuery ?
- AngularJS | ng-copy Directive
- PHP | Ds\Deque copy() Function
- PHP | Ds\Vector copy() Function
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.