Bug #46279 [Com]: next() behaviour inside foreach changed
| From: | dalonso at sistemio dot com | Date: | Thu, 29 Jul 2010 14:13:58 +0000 |
| Subject: | Bug #46279 [Com]: next() behaviour inside foreach changed | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-152939@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=46279&edit=1
ID: 46279
Comment by: dalonso at sistemio dot com
Reported by: jozefchutka at gmail dot com
Summary: next() behaviour inside foreach changed
Status: Bogus
Type: Bug
Package: Arrays related
Operating System: windows
PHP Version: 5.2.6
Block user comment: N
New Comment:
it also happens the same with each method () with each() method
Previous Comments:
------------------------------------------------------------------------
[2008-10-13 09:44:48] tony2001@php.net
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
------------------------------------------------------------------------
[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/bug.php?id=46279&edit=1