[php-src] PR #20304: Fix #20262: array_unique() with SORT_REGULAR misses duplicates

From: Date: Sun, 26 Oct 2025 19:39:34 +0000
Subject: [php-src] PR #20304: Fix #20262: array_unique() with SORT_REGULAR misses duplicates
Groups: php.git-pulls 
Request: Send a blank email to git-pulls+get-33821@lists.php.net to get a copy of this message
Pull Request: https://github.com/php/php-src/pull/20304 Author: jmarble Fixed transitivity violation in zendi_smart_strcmp() that caused sort() and array_unique() to produce incorrect results with mixed numeric and alphanumeric strings. When both strings have numeric prefixes, the comparison now consistently uses numeric comparison, with trailing data as a tie-breaker when the numeric values are equal. The bug occurred because the comparison function would: - Compare "5" vs "10" numerically (5 < 10) - Compare "10" vs "3A" lexically ("1" < "3") - Compare "5" vs "3A" lexically ("5" > "3") This violated transitivity (if a<b and b<c, then a<c must hold), causing sort() to fail to group equal values and array_unique() to miss duplicates. The fix ensures that when both strings have numeric prefixes (even with trailing data), numeric comparison is always used. When numeric values are equal, strings without trailing data are considered "less than" strings with trailing data as a tie-breaker. This maintains backward compatibility while ensuring comparison transitivity.

« previous php.git-pulls (#33821) next »