Prepare Interview

Mock Exams

Make Homepage

Bookmark this page

Subscribe Email Address

Question: What is the purpose of the 'clone' keyword in PHP?
Answer: The 'clone' keyword is used to create a copy of an object. It performs a shallow copy by default, but the __clone() method can be implemented to customize the cloning process.

Example:

class MyClass { 
public $property; 
public function __clone() { // Additional cloning logic if needed } } 
$obj1 = new MyClass(); $obj2 = clone $obj1;
Is it helpful? Yes No

Most helpful rated by users:

©2026 WithoutBook