Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:7857 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 49332 invoked by uid 1010); 16 Feb 2004 00:45:48 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 49304 invoked from network); 16 Feb 2004 00:45:48 -0000 Received: from unknown (HELO shiva.mind.de) (212.42.230.204) by pb1.pair.com with SMTP; 16 Feb 2004 00:45:48 -0000 Received: from [192.168.1.100] (p508EAAA4.dip.t-dialin.net [80.142.170.164]) by shiva.mind.de (Postfix) with ESMTP id DC37C97B59; Mon, 16 Feb 2004 01:45:41 +0100 (CET) Date: Mon, 16 Feb 2004 01:45:53 +0100 Reply-To: Marcus Boerger X-Priority: 3 (Normal) Message-ID: <1435934703.20040216014553@marcus-boerger.de> To: Herr Witten Cc: PHP Development In-Reply-To: <9D7B9586-6018-11D8-8178-000393030CE6@bellsouth.net> References: <6428860843.20040215234759@marcus-boerger.de> <9D7B9586-6018-11D8-8178-000393030CE6@bellsouth.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] clone wars From: helly@php.net (Marcus Boerger) Hello, first as i said do the following to verify: marcus@frodo /usr/src/php5 $ php -r '$a=array(1,2);class t{public $a;function f(){$this->a=&$GLOBALS["a"];}}$o1=new t;$o1->f();var_dump($o1);$o2=clone $o1;$o1->a=2;var_dump($o2);var_dump($o1);' make: `sapi/cli/php' is up to date. object(t)#1 (1) { ["a"]=> &array(2) { [0]=> int(1) [1]=> int(2) } } object(t)#2 (1) { ["a"]=> &int(2) } object(t)#1 (1) { ["a"]=> &int(2) } then remove the '&'. second read the docs and question such things on general@php.net. Monday, February 16, 2004, 1:39:44 AM, you wrote: > More specifically, > This causes a change in $object: > $clone = clone $object; > $clone->troublesomeVariable = array(); > But this doesn't: > $clone = clone $cell; > $clone = null; > $clone->_subElements = array(); > On 15 Feb 2004, at 7:35 PM, Herr Witten wrote: >> It appears that only one of the variables, an array, is being shared >> across these multiple objects, but other array variables are not. >> Moreover, When I make a clone and then set the clone to null, all >> clones made thereafter are correct. >> >> $clone = clone $object; >> $clone = null; >> >> Also, I can't replicate the problem with another class. It only seems >> to be this class. >> >> On 15 Feb 2004, at 5:47 PM, Marcus Boerger wrote: >> >>> Hello, >>> >>> most probably that property is a reference in which case the result is >>> correct. >>> >>> Sunday, February 15, 2004, 11:45:56 PM, you wrote: >>> >>>> It appears that cloning is broken, since a modification to the clone >>>> modifies the original. For my __clone method implementation, I allow >>>> all of the variables to be set by default except for one. But this >>>> problem persists even when I don't modify that one variable. >>> >>> >>> >>> >>> -- >>> Best regards, >>> Marcus mailto:helly@php.net >>> >> >> -- >> PHP Internals - PHP Runtime Development Mailing List >> To unsubscribe, visit: http://www.php.net/unsub.php >> -- Best regards, Marcus mailto:helly@php.net