From: bf at mediaspace dot net
Operating system: Linux
PHP version: 5.0.0RC3
PHP Bug Type: Class/Object related
Bug description: Unexpected behaviour of "new"
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 bug report at http://bugs.php.net/?id=28893&edit=1
--
Try a CVS snapshot (php4): http://bugs.php.net/fix.php?id=28893&r=trysnapshot4
Try a CVS snapshot (php5): http://bugs.php.net/fix.php?id=28893&r=trysnapshot5
Fixed in CVS: http://bugs.php.net/fix.php?id=28893&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=28893&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=28893&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=28893&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=28893&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=28893&r=support
Expected behavior: http://bugs.php.net/fix.php?id=28893&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=28893&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=28893&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=28893&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=28893&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=28893&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=28893&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=28893&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=28893&r=float