#33763 [Opn->Bgs]: array_multisort() affects copy of an array in function

From: Date: Tue, 19 Jul 2005 07:41:44 +0000
Subject: #33763 [Opn->Bgs]: array_multisort() affects copy of an array in function
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-82120@lists.php.net to get a copy of this message
ID: 33763 Updated by: dmitry@php.net Reported By: marceloburegio at gmail dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: Fedora Core 4 and Windows 2000 PHP Version: 5.0.4 New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2005-07-19 06:28:28] 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 ) ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=33763&edit=1

« previous php.bugs (#82120) next »