Fix GH-20262: array_unique() SORT_REGULAR fails to deduplicate with mixed strings #20273
+662
−2
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The Bug
array_unique()withSORT_REGULARwas failing to remove duplicate numeric strings when mixed with alphanumeric strings:Root Cause
Non-transitive comparisons in
SORT_REGULAR(where'5' == 5and5 != '5abc'but'5' < '5abc') broke the sort-based algorithm's assumption that sorting would group duplicates adjacently.Solution
Implemented type-optimized hybrid approach for
SORT_REGULAR:Three-tier algorithm selection:
Key features:
SORT_REGULARtype coercion semantics (1 == '1' == true)Security Hardening
Performance
Improved performance across all data types compared to PHP 8.4.13 while fixing correctness issues.
Backward Compatibility
Tests Added
gh20262.phpt- Minimal regression test for the bugarray_unique_variation_sort_regular.phpt- Comprehensive SORT_REGULAR behavior coverage (16 scenarios)Closes #20262