Req #53341 [Com]: Add a stable sorting flag to sort functions (uasort)

From: Date: Mon, 09 Dec 2019 14:03:18 +0000
Subject: Req #53341 [Com]: Add a stable sorting flag to sort functions (uasort)
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-224172@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=53341&edit=1

 ID:                 53341
 Comment by:         michael dot vorisek at email dot cz
 Reported by:        goetas at lignano dot it
 Summary:            Add a stable sorting flag to sort functions (uasort)
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   any
 PHP Version:        5.3.3
 Block user comment: N
 Private report:     N

 New Comment:

I accept that it is not a bug, but what about offering the stable quarantee in PHP 8.0? Timsort is
used more and more across the industry and except it needs more line of code, it does not perferm
worse than quicksort.

Timsort is now also the default algorithm in Python, Java 7, ...

This will also go hand-in-hand with the PHP philosophy to have only one universal thing.

How can I propose this improvement? Can I have a feedback from the PHP core team?

Sources:
- https://stackoverflow.com/questions/7770230/comparison-between-timsort-and-quicksort
- https://en.wikipedia.org/wiki/Timsort


Previous Comments:
------------------------------------------------------------------------
[2018-03-12 12:21:42] cmb@php.net

Related To: Bug #40888

------------------------------------------------------------------------
[2016-06-14 12:45:06] cmb@php.net

> this bug still appears on php 7.0.6, […]

To make it clear: this is not a bug. The fact that PHP doesn't
make any guarantees about the stability of the sort order is a
deliberate design decision, which is clearly documented[1]:

| If any of these sort functions evaluates two members as equal
| then the order is undefined (the sorting is not stable).

[1] <http://php.net/manual/en/array.sorting.php>

------------------------------------------------------------------------
[2016-06-14 12:31:04] mdg12v at gmail dot com

this bug still appears on php 7.0.6, it was working right on php 5.6.
magento totals sorting component calculating wrong total because of this bug. 
i bet many places affected because of this bug

------------------------------------------------------------------------
[2016-01-29 15:12:15] cw at clement dot hk

@cmb, this is more like a feature request than a bug report.

------------------------------------------------------------------------
[2015-08-13 13:31:12] cmb@php.net

AFAIK PHP 7 uses a stable sort algorithm for small arrays (< 16),
but for larger arrays the algorithm is still not stable.
Furthermore PHP makes no guarantee whether sorting with *sort() is
stable or not.

------------------------------------------------------------------------


The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at

    https://bugs.php.net/bug.php?id=53341


--
Edit this bug report at https://bugs.php.net/bug.php?id=53341&edit=1


Thread (10 messages)

« previous php.bugs (#224172) next »