You are here: Re: PHP brain teaser « PHP Programming Language « IT news, forums, messages
Re: PHP brain teaser

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)

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация