Reply to Re: PHP brain teaser

Your name:

Reply:


Posted by Chung Leong on 01/13/06 16:48

Tim Van Wassenhove wrote:
> On 2006-01-13, Tim Van Wassenhove <timvw@users.sourceforge.net> wrote:
> > 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.
>
> Actually, the new memory is not assigned when the constructor is called, but
> when the $obj->attributes['Length'] is set to 0 in the second method (the
> copy-on-write behaviour of php).
>
> --
> Met vriendelijke groeten,
> Tim Van Wassenhove <http://timvw.madoka.be>

This is the case for the first function. In the second function, the
change to the original object writes through to the cloned object. So
somehow copy-on-write isn't being triggered...

[Back to original 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

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация