|
Posted by Kimmo Laine on 01/13/06 12:36
"Chung Leong" <chernyshevsky@hotmail.com> wrote in message
news:1137121269.941667.278690@g43g2000cwa.googlegroups.com...
> 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?
>
....
> $attr =& $obj->attributes;
Since this is the only difference in the two functions, the bug must be
here.
Let me tell you what I'm guessing, but I'm not sure if this is the case
really. $attr is inside the BritneySpear variable scope, and since it's
assigned reference to $obj->attributes which is copied to $clone, the
$clone->attributes is destroyed as the function exits, since $attr is
destroyed.
--
"En ole paha ihminen, mutta omenat ovat elinkeinoni." -Perttu Sirviφ
spam@outolempi.net | Gedoon-S @ IRCnet | rot13(xvzzb@bhgbyrzcv.arg)
[Back to original message]
|