Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

php __clone() and the "shallow clone"

Tags:

clone

php

What is meant when the results of __clone() is a "Shallow Clone"?

like image 657
Brook Julias Avatar asked Apr 27 '11 19:04

Brook Julias


1 Answers

This means that when the object is cloned, any properties that are reference variables (variables that refer to other objects, rather than a value) will remain references.

A "non-shallow" clone would set the new object's to the values of those properties, rather than leaving them as references.

Note: This means that any changes you make to those references in the cloned object will also be made to the values they reference in the "parent" object.

like image 57
BraedenP Avatar answered Sep 22 '22 23:09

BraedenP