From: freebsd at akruijff dot dds dot nl
Operating system: FreeBSD 6.1
PHP version: 5.1.4
PHP Bug Type: Class/Object related
Bug description: Value changed with passing by reference
Description:
------------
The same objects ends up being added multiple times to the internal array.
I don't understand why this happens.
Reproduce code:
---------------
class X {
private $arr = array();
function add(X &$y) {
$this->arr[] =& $y;
}
}
$x = new X();
for ($i = 0; $i < 10; $i++) {
$y = new X();
echo "$i: adding $y to $x<br>";
$x->add($y);
}
Expected result:
----------------
I'm expecting to see this:
0: adding Object id #2 to Object id #1
1: adding Object id #3 to Object id #1
2: adding Object id #4 to Object id #1
3: adding Object id #5 to Object id #1
4: adding Object id #6 to Object id #1
5: adding Object id #7 to Object id #1
6: adding Object id #8 to Object id #1
7: adding Object id #9 to Object id #1
8: adding Object id #10 to Object id #1
9: adding Object id #11 to Object id #1
Actual result:
--------------
0: adding Object id #2 to Object id #1
1: adding Object id #3 to Object id #1
2: adding Object id #2 to Object id #1
3: adding Object id #3 to Object id #1
4: adding Object id #2 to Object id #1
5: adding Object id #3 to Object id #1
6: adding Object id #2 to Object id #1
7: adding Object id #3 to Object id #1
8: adding Object id #2 to Object id #1
9: adding Object id #3 to Object id #1
--
Edit bug report at http://bugs.php.net/?id=37836&edit=1
--
Try a CVS snapshot (PHP 4.4):
http://bugs.php.net/fix.php?id=37836&r=trysnapshot44
Try a CVS snapshot (PHP 5.2):
http://bugs.php.net/fix.php?id=37836&r=trysnapshot52
Try a CVS snapshot (PHP 6.0):
http://bugs.php.net/fix.php?id=37836&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=37836&r=fixedcvs
Fixed in release:
http://bugs.php.net/fix.php?id=37836&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=37836&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=37836&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=37836&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=37836&r=support
Expected behavior: http://bugs.php.net/fix.php?id=37836&r=notwrong
Not enough info:
http://bugs.php.net/fix.php?id=37836&r=notenoughinfo
Submitted twice:
http://bugs.php.net/fix.php?id=37836&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=37836&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=37836&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=37836&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=37836&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=37836&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=37836&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=37836&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=37836&r=mysqlcfg