In any complex object orient
PHP Program, there are situation that copies of objects. Objects are often
designed mutable which means they contain state information that can change. We
can create copy of an existing object. This is very useful feature of OOP. In
the clone object we can make copy of any Object at run time.
For example we have an object
which has any account detail of any person and we want to use this object to
new account then we cannot do this. First of all we have to make copy this object
as new account.
Program
Example
$abc=new Account ();
$xyz=$abc;
In above we can understand first
of all we make any object ($abc ) of class and we can copy this object ( $abc) to
new object ($zxy) in simple method.
PHP provide new method for copy
object. We can use method “ Clone “ for create duplicate Object
Program
<?php
$object1=new user();
$object1->name=
"admin";
$object2=$object1;
$object2->name="pardeep";
echo "object1 name
is=".$object1->name."<br>";
echo "object2 name
is=".$object2->name;
class user
{
public $name;
}
?>
Here Video Tutorial