php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #33763 array_multisort() affects copy of an array in function
Submitted: 2005-07-19 06:28 UTC Modified: 2005-07-19 09:41 UTC
From: marceloburegio at gmail dot com Assigned:
Status: Not a bug Package: Arrays related
PHP Version: 5.0.4 OS: Fedora Core 4 and Windows 2000
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: marceloburegio at gmail dot com
New email:
PHP Version: OS:

 

 [2005-07-19 06:28 UTC] marceloburegio at gmail dot com
Description:
------------
Using array_multisort() in a function with copy of local array, this affects the original array.

It's same to bug #32031

I solve this changing the code:
$arrSort = $arr;

to:
$arrSort = $arr + array();

Reproduce code:
---------------
function bug_array($arr) {
  $arrSort = $arr;
  array_multisort($arrSort);
}

$arr = array(1, 0);
print_r($arr);

bug_array($arr);
print_r($arr);

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


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


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-07-19 09:41 UTC] dmitry@php.net
This is duplicate of bug #25359.
Behavior is different but reason exactly the same.

array_multisort() - recieves array by value and wotk with tham as with references.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sun Jul 13 13:01:32 2025 UTC