Doc #78992 [Ver->Csd]: Strange behavior of SORT_REGULAR insufficiently documented
| From: | cmb@php.net | Date: | Thu, 19 Dec 2019 19:09:56 +0000 |
| Subject: | Doc #78992 [Ver->Csd]: Strange behavior of SORT_REGULAR insufficiently documented | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-17154@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: Strange behavior of SORT_REGULAR insufficiently
documented
-Status: Verified
+Status: Closed
Type: Documentation Problem
Package: Arrays related
Operating System: Linux
PHP Version: 7.3.13
-Assigned To:
+Assigned To: cmb
Block user comment: N
Private report: N
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation better.
Previous Comments:
------------------------------------------------------------------------
[2019-12-19 19:09:38] cmb@php.net
Automatic comment from SVN on behalf of cmb
Revision: http://svn.php.net/viewvc/?view=revision&revision=348593
Log: Fix #78992: Strange behavior of SORT_REGULAR insufficiently documented
------------------------------------------------------------------------
[2019-12-19 09:33:47] cmb@php.net
While there is already a warning regarding this behavior, I think
the warning message and the description of SORT_REGULAR can be
improved.
------------------------------------------------------------------------
[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