Re: Static Class Member References
| From: | David Harkness | Date: | Wed, 14 Jul 2010 19:28:12 +0000 |
| Subject: | Re: Static Class Member References | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-306894@lists.php.net to get a copy of this message | ||
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
value.
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.
David