Skip to content

Stdlib: sort() unit enum arrays preserve stable order (#16905)#16906

Merged
PurHur merged 1 commit into
masterfrom
agent/issue-16905-sort-unit-enum-stable
Jul 6, 2026
Merged

Stdlib: sort() unit enum arrays preserve stable order (#16905)#16906
PurHur merged 1 commit into
masterfrom
agent/issue-16905-sort-unit-enum-stable

Conversation

@PurHur

@PurHur PurHur commented Jul 6, 2026

Copy link
Copy Markdown
Owner

Summary

  • sort() on unit enum case arrays now preserves stable insertion order when cases are incomparable — matches Zend/php-src array.c behavior (Stdlib: sort() on unit enum arrays reorders cases — must preserve stable order (ext/standard/array.c) #16905).
  • EnumCaseSupport::compareEnumCasesForSort() returns 0 for distinct unit-enum cases (backed enums unchanged: object-handle order).
  • Corrected sort_enum_cases.phpt EXPECT to match Zend output (unit B,A; EOrder C,A,B).
  • Refreshed docs/bootstrap-inventory.md (GetDefinedExcludeDisabledJit.php on vm.php spine path).

php-src reference

  • ext/standard/array.cphp_array_sort enum zval compare
  • Zend/zend_enum.c — unit enum case handles

Verification

./script/docker-exec.sh -- bash -lc 'source script/php-env.sh
php bin/vm.php test/compliance/cases/stdlib/sort_enum_cases.phpt
php bin/vm.php test/repro-maintainer/parity_sort_enum_cases.php
vendor/bin/phpunit --filter SortEnumCasesBuiltinTest
php script/bootstrap-inventory.php --check
'

Output:

# sort_enum_cases.phpt — A B C / B A / A B / C A B (Zend match)
# parity_sort_enum_cases.php — unit enum array ends with EUnit::B, EUnit::A
# SortEnumCasesBuiltinTest — OK (6 tests)
# bootstrap-inventory --check — OK 4170/4170

Closes #16905

Made with Cursor

Unit enum cases are incomparable under SORT_REGULAR — return 0 from
compareEnumCasesForSort() so insertion order matches Zend (php-src array.c).
Refresh bootstrap-inventory.md for GetDefinedExcludeDisabledJit.php spine path.

Verification: php bin/vm.php test/compliance/cases/stdlib/sort_enum_cases.phpt
  vendor/bin/phpunit --filter SortEnumCasesBuiltinTest
  php script/bootstrap-inventory.php --check
Co-authored-by: Cursor <cursoragent@cursor.com>
@PurHur PurHur merged commit e6d6dc3 into master Jul 6, 2026
1 check failed
@PurHur PurHur deleted the agent/issue-16905-sort-unit-enum-stable branch July 6, 2026 12:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stdlib: sort() on unit enum arrays reorders cases — must preserve stable order (ext/standard/array.c)

1 participant