Change record status: 
Project: 
Introduced in branch: 
8.0.x
Introduced in version: 
8.0.3
Description: 

Summary

uasort() does NOT preserve sort order though we presumed it does in many locations in core. For example: Element::children()

We've added a new method to help preserve the sort order.

Considering this render array:

$elements = [
  0 => [
    '#type' => 'checkbox',
    '#title' => 'A',
  ],
  1 => [
    '#type' => 'checkbox',
    '#title' => 'B',
  ],
  2 => [
    '#type' => 'checkbox',
    '#title' => 'C',
    '#weight' => -1000,
  ],
];

Sorted by weight is expected to be sorted as keys 2, 0, 1

Before

uasort($elements, ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
print implode(', ', array_keys($elements));

Produces:
2, 1, 0

After

SortArray::stableUasort($elements, ['Drupal\Component\Utility\SortArray', 'sortByWeightProperty']);
var_dump(array_keys($elements));

Produces:
2, 0, 1

Impacts: 
Module developers
Updates Done (doc team, etc.)
Online documentation: 
Not done
Theming guide: 
Not done
Module developer documentation: 
Not done
Examples project: 
Not done
Coder Review: 
Not done
Coder Upgrade: 
Not done
Other: 
Other updates done