Bug #79844 [Opn->Nab]: Wrong next array index for value add

From: Date: Mon, 13 Jul 2020 10:50:37 +0000
Subject: Bug #79844 [Opn->Nab]: Wrong next array index for value add
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-227993@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=79844&edit=1

 ID:                 79844
 Updated by:         cmb@php.net
 Reported by:        michael dot vorisek at email dot cz
 Summary:            Wrong next array index for value add
-Status:             Open
+Status:             Not a bug
 Type:               Bug
 Package:            Scripting Engine problem
 Operating System:   any
 PHP Version:        7.4.8
-Assigned To:        
+Assigned To:        cmb
 Block user comment: N
 Private report:     N

 New Comment:

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>


Previous Comments:
------------------------------------------------------------------------
[2020-07-13 09:56:15] 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
)



------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=79844&edit=1


Thread (2 messages)

« previous php.bugs (#227993) next »