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 ...
Get Core PHP Programming, Third Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.