Ah, so assigning a reference to a variable already holding a reference
changes that variable's reference only in the same way that unsetting a
reference doesn't unset the other variables referencing the same thing, yes?

$a = 5;
$b = &$a;
print $a;
> 5
unset($b);  // does not affect $a
print $a;
> 5

// and according to Mike's previous message
$b = &$a;
$c = 10;
$b = &$c;  // does not affect $a
print $a
> 5

That makes a lot of sense. If it didn't work this way there would be no easy
way to untangle references. In the case of

    foreach($array as $key => &$value) { ... }

the first value in the array would continuously be overwritten by the next

1. $value gets reference to first array value
2. on each step through the loop, the first array value would be overwritten
by the next value in the loop since $value is forever tied to it by the
initial reference assignment.

That would be a Bad Thing (tm).

Thanks for the clarification, Mike.


Reply via email to