#29992 [Opn]: foreach by reference corrupts the array

From: Date: Mon, 06 Sep 2004 06:04:29 +0000
Subject: #29992 [Opn]: foreach by reference corrupts the array
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-65784@lists.php.net to get a copy of this message
ID: 29992 User updated by: fletch at pobox dot com -Summary: problem with foreach by reference Reported By: fletch at pobox dot com Status: Open Bug Type: Zend Engine 2 problem Operating System: linux PHP Version: 5.0.1 New Comment: changed the summary Previous Comments: ------------------------------------------------------------------------ [2004-09-06 05:54:50] fletch at pobox dot com Description: ------------ foreach with a reference seems to corrupt the last element in an array Reproduce code: --------------- <?php $array = array(1,2,3); foreach( $array as &$item ) { } print_r( $array ); foreach( $array as $item ) { } print_r( $array ); ?> Expected result: ---------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 3 ) Actual result: -------------- Array ( [0] => 1 [1] => 2 [2] => 3 ) Array ( [0] => 1 [1] => 2 [2] => 2 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=29992&edit=1

« previous php.bugs (#65784) next »