Posted by Tim Van Wassenhove on 01/13/06 06:42
On 2006-01-13, Chung Leong <chernyshevsky@hotmail.com> wrote:
> Here's a little brain teaser distilled from a bug that took me a rather
> long time to figure out. The two functions in the example below behave
> differently. The difference is easy to spot, of ocurse. The challenge
> is correctly explaining why this is so. Why does the second function
> seemingly corrupt the cloned copy of an object?
My guess is the following:
When php initializes a new object (copy/clone) it will notice that in the second
method the reference count to $obj->attributes is 2. Therefore it will assign
new memory for the copied/cloned instance. This explains why we see 0 instead of
14.
--
Met vriendelijke groeten,
Tim Van Wassenhove <http://timvw.madoka.be>
[Back to original message]
|