Edit report at http://bugs.php.net/bug.php?id=54351&edit=1
ID: 54351 Updated by: [email protected] Reported by: drake at jetcode dot ru Summary: foreach loop corrupts data -Status: Open +Status: Bogus Type: Bug Package: *General Issues Operating System: CentOS PHP Version: Irrelevant Block user comment: N Private report: N New Comment: This is documented behaviour: foreach with references doesn't behave as you'd expect. Note the warning at http://php.net/foreach about this. Previous Comments: ------------------------------------------------------------------------ [2011-03-22 14:41:33] drake at jetcode dot ru Description: ------------ Affected PHP versions: 5.3.5 5.3.5 5.2.9 Bug reveals only in case when loop variables are SAME and second loop variable is NOT passed by reference. Test script: --------------- $items = array ( array('id' => 1), array('id' => 2), array('id' => 3), array('id' => 4) ); foreach ( $items as &$item ) { $item['foo'] = 'bar'; } // Expected $items id's: 1, 2, 3, 4 // Actualy: 1, 2, 3, 4 foreach ( $items as $item ) { // do nothing } // Expected $items id's: 1, 2, 3, 4 // Actualy: 1, 2, 3, 3 <-- BUG! ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/bug.php?id=54351&edit=1
