How to create a copy of an object in PHP?
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 referenced object created by using ‘=’ operator have same value.