php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79844 Wrong next array index for value add
Submitted: 2020-07-13 09:56 UTC Modified: 2020-07-13 10:50 UTC
From: michael dot vorisek at email dot cz Assigned: cmb (profile)
Status: Not a bug Package: Scripting Engine problem
PHP Version: 7.4.8 OS: any
Private report: No CVE-ID: None
 [2020-07-13 09:56 UTC] michael dot vorisek at email dot cz
Description:
------------
No hidden state should be used for next index.

In example below, empty array is set and cleared immediatelly. When array is clear, next index should be 0 like when the 2nd (set/clear) line would not be presented.

Test script:
---------------
$a = [];

$a[] = 'x'; unset($a[0]); // this should have zero effect

$a[] = 5; // but it has, this value is added under index 1 instead of 0

print_r($a);

Expected result:
----------------
Array
(
    [0] => 5
)


Actual result:
--------------
Array
(
    [1] => 5
)


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-13 10:50 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-07-13 10:50 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

The behavior is explicitly documented[1].  Changing it would
require the RFC process.

[1] <https://www.php.net/manual/en/language.types.array.php#language.types.array.syntax.modifying>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 28 20:01:29 2024 UTC