note 100655 rejected from control-structures.foreach by danbrown
| From: | danbrown@php.net | Date: | Thu, 28 Oct 2010 16:32:02 +0000 |
| Subject: | note 100655 rejected from control-structures.foreach by danbrown | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-173568@lists.php.net to get a copy of this message | ||
Note Submitter: marko dot crni at gmail dot com
----
It took me a whole day of debuging to spot this problem between php versions. This code:
$aArray = array(
1 => null,
2 => null,
3 => null,
);
foreach($aArray as $key => &$val)
{
$val = "Some Value";
foreach($aArray as $Xkey => $Xval) {} // This causes the problem
}
var_dump($aArray);
In php 5.1.6:
array(3) {
[1]=>
string(10) "Some Value"
[2]=>
NULL
[3]=>
NULL
}
In php 5.3.2:
array(3) {
[1]=>
string(10) "Some Value"
[2]=>
string(10) "Some Value"
[3]=>
&string(10) "Some Value"
}