Object replication for deep exploration of object models in PHP5.0
Source: Internet
Author: User
The object model in PHP5 calls an object through reference, but sometimes you may want to create a copy of the object and expect that the change of the original object will not affect the copy. for this purpose, PHP defines a special method called _ clone. like _ construct and _ destruct, the front has two underscores. By default, the _ clone method is used to call an object by referencing an object model in the original PHP5, but sometimes you may want to create a copy of the object, it is expected that the change of the original object will not affect the copy. for this purpose, PHP defines a special method called _ clone. like _ construct and _ destruct, the front has two underscores.
By default, the _ clone method is used to create an object with the same attributes and methods as the original object. if you want to change the default content during cloning, overwrite (attribute or method) in _ clone ).
The clone method can have no parameters, but it also contains the this and that pointers (that points to the copied object ). If you choose to clone yourself, you must be careful to copy any information contained in your object, from that to this. if you use _ clone to copy, PHP does not execute any implicit replication. the following shows an example of how to automate objects using sequence numbers:
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.