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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

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: Thu Apr 25 06:01:35 2024 UTC