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
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:
MUST BE VALID
Solve the problem:
3 + 20 = ?
Subscribe to this entry?

 
 [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-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 16:01:28 2024 UTC