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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
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

Pull Requests

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 18:01:29 2024 UTC