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

Posted by Chung Leong on 01/14/06 05:55

Tim Van Wassenhove wrote:
>
> I still think it's because after this statement the container that holds the
> $obj->attributes will now have is_ref = 1 which seems to lead to a copy of this
> container when $obj is assigned to $clone ($clone = $obj). For some reason php
> doesn't seem to make a deep-copy of the array but simply makes an array with
> references to the original array elements.

That's it. You have got to the root of the problem. During cloning, PHP
does not create a copy of an object property if it is a reference. From
the manual: "Any properties that are references to other variables,
will remain references." The hard part was, of course, recognizing that
$obj->attributes is a reference. It's extremely unintuitive that the
line

$attr =& $obj->attributes;

not only makes $attr a reference, but turns $obj->attributes into a
reference too. Programmers usually don't expect side-effects on the
right side of an assignment operator.

 

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

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