From: nick at itomic dot com
Operating system: Redhat 9
PHP version: 4.3.2
PHP Bug Type: Zend Engine 2 problem
Bug description: functions which accept a reference from inside a loop lose their value

Description:
------------
when a class function accepts a reference parameter & stores that
reference in the object, if that parameter passed in is created &
recreated inside a loop, then the reference that the class points to
changes to the last value of the parameter in the loop.

This is confusing behavious, but it is not necessary buggy behavious no
PHP's behalf, maybe it just requires better doentation.

I can see the situation where an object needs to be passed a reference to
an object, _not_ a copy of a reference (i.e. when dealing with obbject
trees, or lists).

In the below example this may differ from when I am passing in some
pre-existing variable (i.e. a variable returned from a class iterator),
rather than a variable that is created in the loop

Reproduce code:
---------------
<?php
// plz note this is pseudo code

$res = mysql_query(...);

// this part of the code has been tested

while ($row = mysql_fetch_assoc($res))
{
$foos[] =& new foo($row);
}

foreach($foos as $key => $foo)
{
var_dump($foos[$key]->_var);
}

class foo
{
var $_var = NULL;
function foo(&$var)
{
$this->_var =& $var;
}
}


Expected result:
----------------
something like:
array(2) {
["StageID"]=>
string(1) "1"
["StageName"]=>
string(10) "Incomplete"
}
array(2) {
["StageID"]=>
string(1) "2"
["StageName"]=>
string(8) "Complete"
}
array(2) {
["StageID"]=>
string(1) "3"
["StageName"]=>
string(10) "Not Needed"
}
array(2) {
["StageID"]=>
string(1) "4"
["StageName"]=>
string(7) "Waiting"
}
array(2) {
["StageID"]=>
string(1) "5"
["StageName"]=>
string(9) "Submitted"
}

Actual result:
--------------
bool(false)
bool(false)
bool(false)
bool(false)
bool(false)

--
Edit bug report at [url]http://bugs.php.net/?id=25484&edit=1[/url]
--
Try a CVS snapshot (php4): [url]http://bugs.php.net/fix.php?id=25484&r=trysnapshot4[/url]
Try a CVS snapshot (php5): [url]http://bugs.php.net/fix.php?id=25484&r=trysnapshot5[/url]
Fixed in CVS: [url]http://bugs.php.net/fix.php?id=25484&r=fixedcvs[/url]
Fixed in release: [url]http://bugs.php.net/fix.php?id=25484&r=alreadyfixed[/url]
Need backtrace: [url]http://bugs.php.net/fix.php?id=25484&r=needtrace[/url]
Try newer version: [url]http://bugs.php.net/fix.php?id=25484&r=oldversion[/url]
Not developer issue: [url]http://bugs.php.net/fix.php?id=25484&r=support[/url]
Expected behavior: [url]http://bugs.php.net/fix.php?id=25484&r=notwrong[/url]
Not enough info: [url]http://bugs.php.net/fix.php?id=25484&r=notenoughinfo[/url]
Submitted twice: [url]http://bugs.php.net/fix.php?id=25484&r=submittedtwice[/url]
register_globals: [url]http://bugs.php.net/fix.php?id=25484&r=globals[/url]
PHP 3 support discontinued: [url]http://bugs.php.net/fix.php?id=25484&r=php3[/url]
Daylight Savings: [url]http://bugs.php.net/fix.php?id=25484&r=dst[/url]
IIS Stability: [url]http://bugs.php.net/fix.php?id=25484&r=isapi[/url]
Install GNU Sed: [url]http://bugs.php.net/fix.php?id=25484&r=gnused[/url]