|  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
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: louiscelier at gmail dot com
New email:
PHP Version: OS:


 [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: Sat Jul 20 03:02:00 2024 UTC