RE: [PHP-DEV] PHP 4.0 Bug #7511 Updated: References are not properly reassigned with classes

From: Date: Sat, 28 Oct 2000 18:53:01 +0000
Subject: RE: [PHP-DEV] PHP 4.0 Bug #7511 Updated: References are not properly reassigned with classes
References: 1  Groups: php.dev 
Request: Send a blank email to php-dev+get-36271@lists.php.net to get a copy of this message
I think where Mike was mistaken was that he presumed that the new operator would return a reference to the newly created object rather then a value. Which is the source of another question and the topic of a number of bug reports lately. #7511 #7482 #7455 #7454 The problem is that it is not possible for the new operator to return a reference. The ability, I believe, needs to be there. The question is should it return a reference by default or only when explicitly requested. //example by default $joe = new foo(); //$joe will be populated with a reference to the instantiated foo class; //explicit example $joe =& new foo(); //$joe requests a reference to the new object. Either one would work fine. But the decision just needs to be made as to which way to implement it. Thanks for you help, youngm -----Original Message----- From: waldschrott@php.net [mailto:waldschrott@php.net] Sent: Saturday, October 28, 2000 7:17 AM To: php-dev@lists.php.net Subject: [PHP-DEV] PHP 4.0 Bug #7511 Updated: References are not properly reassigned with classes ID: 7511 Updated by: waldschrott Reported By: heathm@effinitylabs.com Status: Closed Bug Type: Class/Object related Assigned To: Comments: no bug here, here´s what you did... 1) created instance of foo on uninitialized $bar 2) created a reference in array $list to $bar (read the chapter "references explained in the manual" if you don´t understand the following) 3) created instance of foo on $bar and it´s referenced array element 4) created another reference in array $list to $bar finally there are 3 structures beeing the same, $bar, array element 1, array element 2 Previous Comments: --------------------------------------------------------------------------- [2000-10-28 08:13:21] heathm@effinitylabs.com I found a rather strange problem with reference to objects. Take the following: <?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. Mike --------------------------------------------------------------------------- Full Bug description available at: http://bugs.php.net/?id=7511 -- 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

« previous php.dev (#36271) next »