php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37836 Value changed with passing by reference
Submitted: 2006-06-18 06:44 UTC Modified: 2006-06-18 12:32 UTC
From: freebsd at akruijff dot dds dot nl Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.1.4 OS: FreeBSD 6.1
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: freebsd at akruijff dot dds dot nl
New email:
PHP Version: OS:

 

 [2006-06-18 06:44 UTC] freebsd at akruijff dot dds dot nl
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

Patches

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-06-18 12:32 UTC] derick@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Sep 10 05:01:28 2024 UTC