ID: 28893
Comment by: bla at discardmail dot com
Reported By: bf at mediaspace dot net
Status: Open
Bug Type: Class/Object related
Operating System: Linux
PHP Version: 5.0.0RC3
New Comment:
i must agree rodolfo, this is correct for php5
but in php4 it is buggy
Previous Comments:
------------------------------------------------------------------------
[2004-06-23 18:50:16] rodolfo at rodsoft dot org
I've just ran your example and found that if you write a[]=$object
(without &), it runs flawlessly.
------------------------------------------------------------------------
[2004-06-23 18:48:02] rodolfo at rodsoft dot org
I've experienced something similar with 'clone' when the cloned
variable is used in mysqli_bind_result, as I said in bug #28870.
------------------------------------------------------------------------
[2004-06-23 13:56:21] bf at mediaspace dot net
Description:
------------
If using "new" in a for-loop it seems that the same instance is re-used
all the time. This is not what is expected, because in terms of OOP the
new-operator schould create a new instance every time.
Tested with 4.3.3 and 5.0RC3
Reproduce code:
---------------
<?
class Test {
var $iterator;
}
$a=array();
for($i=0;$i<10;$i++) {
$object = new Test();
$object->iterator=$i;
$a[]=&$object;
}
foreach($a as $object) {
echo $object->iterator."<br>";
}
?>
Expected result:
----------------
Output should be:
0
1
2
3
4
5
6
7
8
9
Actual result:
--------------
Output actual is:
9
9
9
9
9
9
9
9
9
9
-> The same instance is reused all the time.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=28893&edit=1