Re: PHP 4.0 Bug #7511: References are not properly reassigned with classes
| From: | chrisv at b0rked dot dhs dot org | Date: | Sat, 28 Oct 2000 00:31:04 +0000 |
| Subject: | Re: PHP 4.0 Bug #7511: References are not properly reassigned with classes | ||
| References: | 1 | Groups: | php.dev |
| Request: | Send a blank email to php-dev+get-36232@lists.php.net to get a copy of this message | ||
> <?php
>
> class foo {
> var $Name;
> function foo($name) {
> $this->Name = $name;
> }
> }
>
> $bar = new foo('Mike');
> $list[] =& $bar;
> //unset($bar);
> $bar = new foo('Jeremy');
> $list[] =& $bar;
>
> while(list($key, $val) = each($list))
> echo "<br>$key = $val->Name";
>
> ?>
>
> When going through the loop and echoing the Name parameter the both
> return Jeremy. If I unset $bar first (by uncommenting it) it works
> fine. I'm not exactly sure what's going on but it is rather strange.
>
That's how it's supposed to work-- by assigning &$bar to both list[0] and
list[1], they're essentially the same thing. If you don't want that to
happen, you have to either do --
$list[] = new foo('Mike');
$list[] = new foo('Jeremy');
-- or use unset($bar).
Chris