RE: [PHP-DEV] PHP 4.0 Bug #7511: References are not properly reassigned with classes
| From: | Mike Heath | Date: | Sat, 28 Oct 2000 00:55:46 +0000 |
| Subject: | RE: [PHP-DEV] 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-36234@lists.php.net to get a copy of this message | ||
That's very true. Thank you for the correction. I guess I was assuming new
was returning a reference for some reason.
Thanks,
Mike
-----Original Message-----
From: chrisv@b0rked.dhs.org [mailto:chrisv@b0rked.dhs.org]
Sent: Friday, October 27, 2000 6:31 PM
To: heathm@effinitylabs.com
Cc: php-dev@lists.php.net
Subject: Re: [PHP-DEV] PHP 4.0 Bug #7511: References are not properly
reassigned with classes
> <?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
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: php-dev-unsubscribe@lists.php.net
For additional commands, e-mail: php-dev-help@lists.php.net
To contact the list administrators, e-mail: php-list-admin@lists.php.net