#45708 [Opn->Bgs]: uasort overwrite bug

From: Date: Mon, 04 Aug 2008 14:19:26 +0000
Subject: #45708 [Opn->Bgs]: uasort overwrite bug
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-127579@lists.php.net to get a copy of this message
ID: 45708 Updated by: jani@php.net Reported By: watermark86 at gmail dot com -Status: Open +Status: Bogus Bug Type: Arrays related Operating System: ubuntu 8.04 PHP Version: 5.2.6 New Comment: Quite expected: $row is still reference to that one entry. You modify it to 0 in the for() clause.. Previous Comments: ------------------------------------------------------------------------ [2008-08-04 13:42:56] watermark86 at gmail dot com Description: ------------ uasort overwrites the last element in a large associative array with incrementing numbers Reproduce code: --------------- $detaildata = array(); for($i = 0; $i < 6; $i++) { $lid = rand(1,200); $numpeople = rand(0,12); for($p = 0; $p < $numpeople; $p++) { $pid = rand(1,200); $detaildata[$lid][$pid] = array("string data","string data",$pid); } } $detaildata[9][44] = array("string data","string data",44); // foreach($detaildata as &$row) { uasort($row,CalSortCallback); } // echo is_array($detaildata[9])?'yes':'no'; for($row = 0; $row < 5; $row++) { echo is_array($detaildata[9])?'yes':$detaildata[9]; } // function CalSortCallback($a,$b) { return strcmp($a[1],$b[1]); } Expected result: ---------------- it should print 6 yeses yesyesyesyesyesyes Actual result: -------------- it prints yes01234 ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=45708&edit=1

« previous php.bugs (#127579) next »