/*
+-------------------------------------------------- ----------------------------------+
| = This article is read by Haohappy<
| = Notes from the Chapter Classes and Objects
| = Translation + personal experience
| = To avoid possible unnecessary trouble, please do not reprint, thank you
| = We welcome criticisms and corrections, and hope to make progress together with all PHP enthusiasts!
| = PHP5 Research Center: http://blog.csdn.net/haohappy2004
+---------- -------------------------------------------------- ------------------+
*/
Section 5--Clone
Object model in PHP5 by reference to call the object, but sometimes you may want to create a copy of the object, and hope that changes to the original object will not affect the copy. For this purpose, PHP defines a special method called __clone. Like __construct and _ _destruct is the same, preceded by two underscores.
By default, using the __clone method will create an object with the same properties and methods as the original object. If you want to change the default content when cloning, you have to Override (property or method) in __clone.
The clone method can have no parameters, but it contains both this and that pointers (that points to the copied object). If you choose to clone yourself, you have to be careful Copy any information you want your object to contain, from that to this. If you use __clone to copy. PHP will not perform any implicit copying.
The following shows an automated object using serial ordinals Example: