Bug->Doc #78992 [Opn->Ver]: Strange behavior of SORT_REGULAR insufficiently documented
| From: | cmb@php.net | Date: | Thu, 19 Dec 2019 09:33:47 +0000 |
| Subject: | Bug->Doc #78992 [Opn->Ver]: Strange behavior of SORT_REGULAR insufficiently documented | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17145@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
Updated by: cmb@php.net
Reported by: kfiadeg at gmail dot com
-Summary: Inconsistent sorting
+Summary: Strange behavior of SORT_REGULAR insufficiently
documented
-Status: Open
+Status: Verified
-Type: Bug
+Type: Documentation Problem
Package: Arrays related
Operating System: Linux
PHP Version: 7.3.13
Block user comment: N
Private report: N
New Comment:
While there is already a warning regarding this behavior, I think
the warning message and the description of SORT_REGULAR can be
improved.
Previous Comments:
------------------------------------------------------------------------
[2019-12-18 17:15:41] as@php.net
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
------------------------------------------------------------------------
[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