Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:22654 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 81014 invoked by uid 1010); 3 Apr 2006 14:29:36 -0000 Delivered-To: ezmlm-scan-internals@lists.php.net Delivered-To: ezmlm-internals@lists.php.net Received: (qmail 80998 invoked from network); 3 Apr 2006 14:29:36 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 3 Apr 2006 14:29:36 -0000 X-Host-Fingerprint: 195.186.18.62 mail13.bluewin.ch Received: from ([195.186.18.62:38095] helo=mail13.bluewin.ch) by pb1.pair.com (ecelerity 2.0 beta r(6323M)) with SMTP id 8F/59-09123-E4131344 for ; Mon, 03 Apr 2006 10:29:34 -0400 Received: from [10.0.0.1] (85.0.171.45) by mail13.bluewin.ch (Bluewin 7.2.072.1) id 4431026B0000C6D8 for internals@lists.php.net; Mon, 3 Apr 2006 14:29:31 +0000 Message-ID: <44313146.8050704@php.net> Date: Mon, 03 Apr 2006 16:29:26 +0200 User-Agent: Thunderbird 1.5 (Windows/20051201) MIME-Version: 1.0 CC: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] A reference problem From: colder@php.net (Etienne Kneuss) Hi, Karoly Negyesi a écrit : > > Please note that the only difference between f1 and f2 that the first > > records the return value of f3() into a variable. However, this > > changes the output: > > > > array(1) { > > ["foo"]=> > > &string(3) "bar" > > } > > array(1) { > > ["foo"]=> > > string(3) "bar" > > } > > > > Is this a bug? Or I miss something? > When copying an array containing a reference, the reference is keeped. : $value = 'foo'; $array = array (&$value); $array2 = $array; $array2[0] = 'bar'; echo $array[0]; // bar Here, the &string(3) means that it's referenced. Indeed, $throwaway contains a reference to it. change your f1 to this : function f1() { global $a; $array = array(); $throwaway = f3($array); unset($throwaway); var_dump($a); } And the "&" will obviously disappear, as the reference no longer exists. Kind regards -- Etienne Kneuss http://www.colder.ch/ colder@php.net -- Etienne Kneuss http://www.colder.ch/ colder@php.net