While venus is crossing the sun I'm trying to model a tree using two arrays; one containing the structure of the tree and the other containing the data of the nodes.
The second array also contains pointers to 'subtrees' of the first array. Anyway, I discovered a strange behavior when I dumped the tree before and after making the pointers.
Example:


<?php
$tree = array( 1 => array( 2 => 'foo' ) );

var_dump($tree);

$b = &$tree[1];

var_dump($tree);
?>

This code will output the following:
array(1) {
  [1]=>
  array(1) {
    [2]=>
    string(3) "foo"
  }
}
array(1) {
  [1]=>
  &array(1) {
    [2]=>
    string(3) "foo"
  }
}

As you can see the original tree now contains a pointer, how can that be, I didn't change the original array!?
So what I'd like to know is: Is this intended behavior, and if so: why does it work like this and would it make some operations impossible?


Taco

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



Reply via email to