Home  >  Article  >  php教程  >  php object-oriented clone object

php object-oriented clone object

WBOY
WBOYOriginal
2016-08-04 08:57:101397browse

In the previous PHP object-oriented object and reference, we tried to copy the object in the way of "$b=$a" to pass the value (content) of the object, but the result was to pass the address of the object. At the end, in order to solve The question of copying objects mentioned the cloning method. Next, let’s talk about php object-oriented cloneobject.


We have known before that when calling an object using a pass-by reference, the actual call is the same object. Sometimes it is necessary to create a copy of the object. When changing the original object, we do not want to affect the copy. In PHP You can clone an identical object based on the current object. The cloned copy is completely independent of the original two objects and does not interfere with each other.


Object Clone

Use "clone" keyword in php to clone objects.

<?php
class Person {
           public $name;
                                            
function
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn