Bug #79364 [PATCH]: When copy empty array, next key is unspecified.
| From: | cmb@php.net | Date: | Tue, 10 Mar 2020 15:18:18 +0000 |
| Subject: | Bug #79364 [PATCH]: When copy empty array, next key is unspecified. | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-226007@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
Patch added by: cmb@php.net
Reported by: yuubiseiharukana at gmail dot com
Summary: When copy empty array, next key is unspecified.
Status: Open
Type: Bug
Package: Arrays related
Operating System: Any
PHP Version: 7.4.3
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[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