Bug #78992 [Com]: Inconsistent sorting

From: Date: Wed, 18 Dec 2019 17:15:41 +0000
Subject: Bug #78992 [Com]: Inconsistent sorting
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224396@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=78992&edit=1 ID: 78992 Comment by: as@php.net Reported by: kfiadeg at gmail dot com Summary: Inconsistent sorting Status: Open Type: Bug Package: Arrays related Operating System: Linux PHP Version: 7.3.13 Block user comment: N Private report: N New Comment: Interesting. The string "8e7" is interpreted differently by zendi_smart_strcmp[0] depending on the element it is being compared to. If the other element is numeric, it is interpreted as scientific notation (8*10^7). If the other element is non-numeric, it is interpreted as a string. As a result, the element "8e7" effectively takes on different values for each iteration of the sort algorithm. Changing this behavior would be a bc break. However it feels worth documenting that SORT_REGULAR has counter-intuitive / buggy behavior. [0] https://github.com/php/php-src/blob/2a76384b87cd8c48c626641ac9e820e426d47de8/Zend/zend_operators.c#L2724-L2773 Previous Comments: ------------------------------------------------------------------------ [2019-12-18 15:07:57] kfiadeg at gmail dot com Description: ------------ I've encountered inconsistency with sorting string arrays. Sorting arrays that have the same set of elements but in different order produce different results when used with sort() function (without any flags). Test script: --------------- https://pastebin.com/4uKk37by Expected result: ---------------- If arrays have the same set of elements, performing sort() on each of them should give the same order of elements for every array. Actual result: -------------- After sorting array elements keep different order. ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=78992&edit=1

« previous php.bugs (#224396) next »