php.net |  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.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: louiscelier at gmail dot com
New email:
PHP Version: OS:

 

 [2016-09-06 17:28 UTC] louiscelier at gmail dot com
Description:
------------
---
From manual page: http://www.php.net/function.next
---

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

https://3v4l.org/hg1Of

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);
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2016-09-06 17:32 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2016-09-06 17:32 UTC] nikic@php.net
This behavior changed as part of https://wiki.php.net/rfc/php7_foreach, which was a significant change to foreach semantics. It will not be applied to PHP 5.6.
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Wed Jul 28 21:01:24 2021 UTC