From: [EMAIL PROTECTED] Operating system: Linux PHP version: 4.3.2 PHP Bug Type: Unknown/Other Function Bug description: strange behaviour with references
Description: ------------ we just detected a strange behaviour with references and foreach: after the foreach() is done in the sample code the & disappear in the var_dump for the first two elements, the third is of course still a valid reference because $row exists i tried to reproduce that effect in different ways but it only happens when using a foreach Reproduce code: --------------- <pre><?php $arr = array(1, 2, 3); for ($i = 0; $i < count($arr); $i++) { $row =& $arr[$i]; $row = $row * $row; } var_dump($arr); reset ($arr); while (list(, $value) = each ($arr)) echo "value: $value\n"; var_dump($arr); foreach($arr AS $value) echo "value: $value\n"; var_dump($arr); ?> Actual result: -------------- array(3) { [0]=> &int(1) [1]=> &int(4) [2]=> &int(9) } value: 1 value: 4 value: 9 array(3) { [0]=> &int(1) [1]=> &int(4) [2]=> &int(9) } value: 1 value: 4 value: 9 array(3) { [0]=> int(1) [1]=> int(4) [2]=> &int(9) } -- Edit bug report at http://bugs.php.net/?id=24486&edit=1 -- Try a CVS snapshot: http://bugs.php.net/fix.php?id=24486&r=trysnapshot Fixed in CVS: http://bugs.php.net/fix.php?id=24486&r=fixedcvs Fixed in release: http://bugs.php.net/fix.php?id=24486&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=24486&r=needtrace Try newer version: http://bugs.php.net/fix.php?id=24486&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=24486&r=support Expected behavior: http://bugs.php.net/fix.php?id=24486&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=24486&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=24486&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=24486&r=globals PHP 3 support discontinued: http://bugs.php.net/fix.php?id=24486&r=php3 Daylight Savings: http://bugs.php.net/fix.php?id=24486&r=dst IIS Stability: http://bugs.php.net/fix.php?id=24486&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=24486&r=gnused