#43501 [NEW]: foreach by reference corrupts the array (reopened)
| From: | gerry dot spm at gmail dot com | Date: | Wed, 05 Dec 2007 08:37:45 +0000 |
| Subject: | #43501 [NEW]: foreach by reference corrupts the array (reopened) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-120377@lists.php.net to get a copy of this message | ||
From: gerry dot spm at gmail dot com
Operating system: Linux
PHP version: 5.2.5
PHP Bug Type: Scripting Engine problem
Bug description: foreach by reference corrupts the array (reopened)
Description:
------------
bug #29992 did not prove that the array was being modified by foreach,
however this code does. According to var_dump() the last element starts as
a "string" and after the foreach is a "reference to a string".
Reproduce code:
---------------
$foo = array('three', 'blind', 'mice');
var_dump($foo);
foreach($foo as &$elmnt){}
var_dump($foo);
Expected result:
----------------
array(3) {
[0]=>
string(5) "three"
[1]=>
string(5) "blind"
[2]=>
string(4) "mice"
}
array(3) {
[0]=>
string(5) "three"
[1]=>
string(5) "blind"
[2]=>
string(4) "mice"
}
Actual result:
--------------
array(3) {
[0]=>
string(5) "three"
[1]=>
string(5) "blind"
[2]=>
string(4) "mice"
}
array(3) {
[0]=>
string(5) "three"
[1]=>
string(5) "blind"
[2]=>
&string(4) "mice"
}
--
Edit bug report at http://bugs.php.net/?id=43501&edit=1
--
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=43501&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=43501&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=43501&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=43501&r=trysnapshot60
Fixed in CVS: http://bugs.php.net/fix.php?id=43501&r=fixedcvs
Fixed in release: http://bugs.php.net/fix.php?id=43501&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=43501&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=43501&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=43501&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=43501&r=support
Expected behavior: http://bugs.php.net/fix.php?id=43501&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=43501&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=43501&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=43501&r=globals
PHP 3 support discontinued: http://bugs.php.net/fix.php?id=43501&r=php3
Daylight Savings: http://bugs.php.net/fix.php?id=43501&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=43501&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=43501&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=43501&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=43501&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=43501&r=mysqlcfg