6.5. Cloning
The object model in PHP 5 treats objects in a unique way by implementing an implicit by-reference paradigm. In some situations, you may wish to create a replica of an object so that changes to the replica are not reflected in the original object. For that purpose, PHP defines a special method, named __clone. As with __construct and __destruct, use two underscores for the first two characters of the method name.
Every object has a default implementation for __clone. The default implementation creates a new object containing the same values and resources as the original object. If you wish to override this default implementation, you may declare your own version of __clone in your class.
The clone method accepts no arguments, but it ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access