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/ [EMAIL PROTECTED]


-- 
Etienne Kneuss

http://www.colder.ch/
[EMAIL PROTECTED]

-- 
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to