#46279 [Opn->Bgs]: next() behaviour inside foreach changed

From: Date: Mon, 13 Oct 2008 09:44:48 +0000
Subject: #46279 [Opn->Bgs]: next() behaviour inside foreach changed
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-129664@lists.php.net to get a copy of this message
ID: 46279 Updated by: tony2001@php.net Reported By: jozefchutka at gmail dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: windows PHP Version: 5.2.6 New Comment: Note: Unless the array is referenced, foreach operates on a copy of the specified array and not the array itself. foreach has some side effects on the array pointer. Don't rely on the array pointer during or after the foreach without resetting it. http://php.net/foreach Previous Comments: ------------------------------------------------------------------------ [2008-10-12 11:14:40] jozefchutka at gmail dot com Description: ------------ there is a bug in 5.2.6 causing unexpected results when using next() function indisde foreach. Results from php 5.1, or 4.x are as expected. Reproduce code: --------------- <?php $arr=array('a','b','c', 'd','e'); foreach($arr as $a){ print_r($a); echo " next is: "; print_r(next($arr)); echo "<br />"; } ?> Expected result: ---------------- a next is: b b next is: c c next is: d d next is: e e next is: Actual result: -------------- a next is: c b next is: d c next is: e d next is: e next is: ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=46279&edit=1

« previous php.bugs (#129664) next »