|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #73033 When in a foreach, the next function return the n+2 element
Submitted: 2016-09-06 17:28 UTC Modified: 2016-09-06 17:32 UTC
From: louiscelier at gmail dot com Assigned:
Status: Wont fix Package: Arrays related
PHP Version: 5.6.25 OS: linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
Solve the problem:
38 + 17 = ?
Subscribe to this entry?

 [2016-09-06 17:28 UTC] louiscelier at gmail dot com
From manual page:

When in a foreach on an array, the next function used on the same array does not return the n+1 element but the n+2 element.

This bug appeared with the 5.2.4 version of PHP and it is still present on 5.6.*

It is absend of version7 and of hhvm

Test script:
$array = array(array(0,0), array(0,5), array(5,5), array(5,0), array(0,0));

foreach ($array as $point) {
    $next = next($array);
    var_dump($point, $next);


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-06 17:32 UTC]
-Status: Open +Status: Wont fix
 [2016-09-06 17:32 UTC]
This behavior changed as part of, which was a significant change to foreach semantics. It will not be applied to PHP 5.6.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Feb 27 00:01:26 2024 UTC