php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77014 Array traversal issues PHP 7+
Submitted: 2018-10-15 15:09 UTC Modified: -
From: mishamosher at gmail dot com Assigned:
Status: Open Package: Arrays related
PHP Version: 7.2.11 OS:
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2018-10-15 15:09 UTC] mishamosher at gmail dot com
Description:
------------
There is a different behaviour between PHP 5.x and 7.x when traversing arrays.

I can not find if this is intended, so I'm supposing its a bug.

Test script:
---------------
https://3v4l.org/YNJ18

Expected result:
----------------
I expect the same output on PHP 5.x and 7.x.

Actual result:
--------------
The outputs differ between PHP 5.x and 7.x.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2018-11-26 14:34 UTC] george dot banyard at gmail dot com
I don't think this is a bug with the array traversal but more with the copying of the array state when the function is executed.
If you reverse the order of execution as shown here: https://3v4l.org/l1bYA

You get the same result in PHP5.x and 7.x

Only difference that I know of is that before PHP7 foreach would use the internal pointer of the array which isn't necessary any more.

So maybe there was a pointer reset mechanism for all loops which has been removed during the transition from 5 to 7.

Also I do think the new behaviour in this case is Intended and wouldn't considered it a bug.
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Tue Jun 25 00:01:26 2019 UTC