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

Posted by Mladen Gogala on 01/13/06 17:12

On Thu, 12 Jan 2006 19:01:10 -0800, Chung Leong 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?

It doesn't. You are not writing to the clone, you are writing to the
original. You are setting the original data to "", not the clone. Clone
is a bitwise copy, not a reference. If you want it to be something else
then a bitwise copy, you have to define the __clone function. What you
should have written in place of "clone" is $clone =& $obj; Then the
assignment would work and the function would return a reference to
the original object, which is also passed by reference.


--
http://www.mgogala.com

 

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

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