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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sat Jun 01 23:01:28 2024 UTC