|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-06-18 12:32 UTC] derick@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 18:00:01 2025 UTC |
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