php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #78529 Internal Array Pointer still points to NULL after adding element
Submitted: 2019-09-12 15:35 UTC Modified: 2019-09-12 16:07 UTC
From: philipp at atelierdisko dot de Assigned:
Status: Open Package: Arrays related
PHP Version: 7.3.9 OS: Linux & Darwin
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: philipp at atelierdisko dot de
New email:
PHP Version: OS:

 

 [2019-09-12 15:35 UTC] philipp at atelierdisko dot de
Description:
------------
This problem occurs in Version 7.3.0 - 7.40beta4.

Steps to reproduce:
1. Have an array $a with elements and integer keys
2. Let the internal pointer point beyond the end of the elements list using next($a)
3. Set a value by key where key is lower then the lowest existing key in $a
4. Call key($a)

I expect key($a) to return the key of the element I just added (like it did before 7.3.0), but it returns null.

I have prepared a 3v4l script that shows the problem:
https://3v4l.org/DoFve

Thanks for having a look at this. I can provide more context if needed.

Test script:
---------------
$data = [1 => true];
next($data);
var_dump(key($data));
$data[0] = true;
var_dump(key($data));

Expected result:
----------------
NULL
int(0)

Actual result:
--------------
NULL
NULL

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-09-12 16:07 UTC] requinix@php.net
Is this documented behavior?
 [2019-09-12 16:55 UTC] philipp at atelierdisko dot de
I was looking for hints to this in the following places:
https://www.php.net/manual/en/function.key.php
https://github.com/php/php-langspec
https://www.php.net/manual/en/doc.changelog.php
 
PHP Copyright © 2001-2019 The PHP Group
All rights reserved.
Last updated: Wed Oct 16 05:01:26 2019 UTC