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
Votes:1
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
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
Have you experienced this issue?
Rate the importance of this bug to you:

 [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: Thu Oct 24 05:01:28 2019 UTC