johnmerlino1 Posted July 30, 2014 Share Posted July 30, 2014 I came across the PHP clone method. Does this clone first level fields and methods or does it also do deep copying e.g. copying references to those fields. For example, a field may be an array. Does it make a copy of the actual array or does it refer to the same array position in memory, so if the original changes, then the copy's changes as well? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 30, 2014 Share Posted July 30, 2014 It works the same way as assignment: scalars and arrays are deep-copied while objects and resources (even within arrays) get "references". Not real references but copies of the class/resource pointer, if you will. Technically they're all "references" to start with but PHP does a real copy when you attempt to change the value, so practically speaking it's a copy. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.