> 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? > The truth of it is, this was true in PHP4 as well, we just didn't show it at the time, and yes: It's intended behavior.
Every "variable" in PHP is a pair. The $foo label that you use to refer to it in your script, and the actual value in memory (referred to as a zval). When you make a reference (using the & operator) the new label is created to point to the same zval as the original label. The zval itself doesn't know which label was first and which came second, it only knows that two labels refer to it in a reference manner (there are non-reference manners as well but let's not confuse the issue here). So when the value is output (regardless of which label was followed to output it), PHP says "This value is referenced by two or more labels." and throws that '&' indicator onto the output. $foo = 1; /* $foo (label) --------> 1 (value) (is_ref=0, refcount=1) */ $bar = &$foo; /* $foo (label) ----------> 1 (value) */ /* $bar (label) -------/ is_ref=1, refcount=2 */ Hope that helps. -Sara -- PHP Internals - PHP Runtime Development Mailing List To unsubscribe, visit: http://www.php.net/unsub.php