Bug #79364 [Opn->Csd]: When copy empty array, next key is unspecified.
| From: | cmb@php.net | Date: | Wed, 11 Mar 2020 07:58:20 +0000 |
| Subject: | Bug #79364 [Opn->Csd]: When copy empty array, next key is unspecified. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226017@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=79364&edit=1
ID: 79364
Updated by: cmb@php.net
Reported by: yuubiseiharukana at gmail dot com
Summary: When copy empty array, next key is unspecified.
-Status: Open
+Status: Closed
Type: Bug
Package: Arrays related
Operating System: Any
PHP Version: 7.4.3
Block user comment: N
Private report: N
New Comment:
Automatic comment on behalf of cmbecker69@gmx.de
Revision: http://git.php.net/?p=php-src.git;a=commit;h=2462f2dab185f53544f2c5335ba6c16a007f3c71
Log: Fix #79364: When copy empty array, next key is unspecified
Previous Comments:
------------------------------------------------------------------------
[2020-03-10 15:18:18] cmb@php.net
The following pull request has been associated:
Patch Name: Fix #79364: When copy empty array, next key is unspecified
On GitHub: https://github.com/php/php-src/pull/5253
Patch: https://github.com/php/php-src/pull/5253.patch
------------------------------------------------------------------------
[2020-03-10 14:38:28] yuubiseiharukana at gmail dot com
Description:
------------
Copy array.
When arrays next index=2 and max key=2, next key is both 2.
When arrays next index=2 and max key=1, next key is both 2.
When arrays next index=2 and max key=0, next key is 0 or 2.
Test script:
---------------
https://3v4l.org/TYc10
$a = [1, 2];
unset($a[1], $a[0]);
$b = $a;
$a[] = 3;
$b[] = 4;
var_dump($a, $b); // $a = [0=>3] $b = [2=>4]
When increase variables, only the last one take over key.
Expected result:
----------------
Always same key whth $a and $b.
Actual result:
--------------
Same key when array is not empty.
Not same key when array is empty.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=79364&edit=1