Re: A reference problem

From: Date: Mon, 03 Apr 2006 14:29:26 +0000
Subject: Re: A reference problem
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-22654@lists.php.net to get a copy of this message
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

« previous php.internals (#22654) next »