php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25359 array_multisort() doesn't work in a function if array is global or reference
Submitted: 2003-09-02 06:58 UTC Modified: 2005-08-10 14:03 UTC
Votes:19
Avg. Score:4.3 ± 1.1
Reproduced:17 of 17 (100.0%)
Same Version:8 (47.1%)
Same OS:9 (52.9%)
From: matschek at gmx dot de Assigned: dmitry (profile)
Status: Closed Package: Scripting Engine problem
PHP Version: 5CVS, 4CVS (2005-07-30) OS: *
Private report: No CVE-ID: None
 [2003-09-02 06:58 UTC] matschek at gmx dot de
Description:
------------
When using array_multisort in a funciton, and the array is set to "global", array_multisort fails to sort the array.

Reproduce code:
---------------
function does_work() {
    $data = array('first', 'fifth', 'second', 'forth', 'third');
    $sort = array(1, 5, 2, 4, 3);
    array_multisort($sort, $data);
    print_r($data);
}

function does_not_work() {
    global $data;
    $data = array('first', 'fifth', 'second', 'forth', 'third');
    $sort = array(1, 5, 2, 4, 3);
    array_multisort($sort, $data);
    print_r($data);
}

echo "function does_work():\n";
does_work();

echo "\n\nfunction does_not_work():\n";
does_not_work();

Expected result:
----------------
function does_work():
Array
(
    [0] => first
    [1] => second
    [2] => third
    [3] => forth
    [4] => fifth
)


function does_not_work():
Array
(
    [0] => first
    [1] => second
    [2] => third
    [3] => forth
    [4] => fifth
)

Actual result:
--------------
function does_work():
Array
(
    [0] => first
    [1] => second
    [2] => third
    [3] => forth
    [4] => fifth
)


function does_not_work():
Array
(
    [0] => first
    [1] => fifth
    [2] => second
    [3] => forth
    [4] => third
)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-25 10:05 UTC] sniper@php.net
See also bug #32817 (uses references)


 [2005-07-18 02:46 UTC] sniper@php.net
Still verified. Dmitry, can you take a look?

 [2005-08-10 14:03 UTC] dmitry@php.net
Fixed in CVS HEAD and PHP_5_1.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Mar 19 07:01:29 2024 UTC