# Dort behaviour change on php7 master

- Thread: https://externals.io/message/81170
- Original archive: https://news-web.php.net/php.internals/81170
- Started by Pascal Chevrel on 2015-01-26T19:14:46+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #81170 — Pascal Chevrel — 2015-01-26T19:14:46+00:00

URL: https://externals.io/message/81170#81170

Hi all,

I just compiled master to test my main application and the good news is 
that I have no functional regression and some of the views get a 
considerable speed up (like, page generation divided by two!).

I had one unit test failing and I reduced that to a simple testcase that 
I put there:

http://3v4l.org/4tGv6

Sorting in php master in this specific case is now different on PHP 7 
than on 5.3-5.6 (and actually different than PHP 7 at the beginning of 
the month). The sorting order is now the same as HHVM.

I think the HHVM behaviour makes more sense in this case as I don't see 
why the resulting array should be reversed in this sorting case where 
all lengths are equal, but on the other hand the current behaviour is 
probably 10 years old and maybe it could cause bigger problems in other 
apps than a unit test to update.

Just that you know, in case it matters.

Cheers

Pascal

---

## #81171 — Rasmus Lerdorf — 2015-01-26T19:19:27+00:00

URL: https://externals.io/message/81170#81171 · In reply to: #81170

> Hi all,
> 
> I just compiled master to test my main application and the good news is
> that I have no functional regression and some of the views get a
> considerable speed up (like, page generation divided by two!).
> 
> I had one unit test failing and I reduced that to a simple testcase that
> I put there:
> 
> http://3v4l.org/4tGv6
> 
> Sorting in php master in this specific case is now different on PHP 7
> than on 5.3-5.6 (and actually different than PHP 7 at the beginning of
> the month). The sorting order is now the same as HHVM.
> 
> I think the HHVM behaviour makes more sense in this case as I don't see
> why the resulting array should be reversed in this sorting case where
> all lengths are equal, but on the other hand the current behaviour is
> probably 10 years old and maybe it could cause bigger problems in other
> apps than a unit test to update.
> 
> Just that you know, in case it matters.

Yeah, this is a known change and the documentation has had a note about
not relying on the ordering of equal elements. Although the note in the
manual is probably a bit too geeky. It should be more explicit and talk
about the effect rather than the cause:

    Note: Like most PHP sorting functions, `sort()` uses an
          implementation of » Quicksort. The pivot is chosen in the
          middle of the partition resulting in an optimal time for
          already sorted arrays. This is however an implementation
          detail you shouldn't rely on.

-Rasmus
