php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79364 When copy empty array, next key is unspecified.
Submitted: 2020-03-10 14:38 UTC Modified: 2020-03-11 08:14 UTC
From: yuubiseiharukana at gmail dot com Assigned: cmb (profile)
Status: Closed Package: Arrays related
PHP Version: 7.4.3 OS: Any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: yuubiseiharukana at gmail dot com
New email:
PHP Version: OS:

 

 [2020-03-10 14:38 UTC] 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.


Patches

Pull Requests

Pull requests:

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-03-10 15:18 UTC] 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-11 07:58 UTC] cmb@php.net
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
 [2020-03-11 07:58 UTC] cmb@php.net
-Status: Open +Status: Closed
 [2020-03-11 08:14 UTC] cmb@php.net
-Assigned To: +Assigned To: cmb
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Oct 27 16:01:27 2024 UTC