Problem Statement
Explain object cloning in PHP with example.
Explanation
Cloning creates a new object with the same properties as another object. PHP provides the clone keyword for this. You can also define a __clone() method to modify behavior after cloning.
Example:
class User { public $name; }
$u1 = new User(); $u1->name = 'John';
$u2 = clone $u1; $u2->name = 'Sam';
Now $u1 and $u2 are separate objects.
Code Solution
SolutionRead Only
$obj2 = clone $obj1;
