strcoll() And SORT_LOCALE_STRING Are Deprecated
strcoll() compares strings according to the current locale, and the SORT_LOCALE_STRING flag makes sort() and related functions do the same. Until PHP 8.6, both relied silently on the global, thread-unsafe locale set by setlocale(). In PHP 8.6, using either strcoll() or SORT_LOCALE_STRING emits a deprecation notice recommending the intl extension’s Collator class instead.
PHP code
<?php
var_dump(strcoll('a', 'b'));
$arr = ['banana', 'Apple', 'cherry'];
sort($arr, SORT_LOCALE_STRING);
var_dump($arr);
?>
Before
int(-1)
array(3) {
[0]=>
string(5) "Apple"
[1]=>
string(6) "banana"
[2]=>
string(6) "cherry"
}
After
PHP Deprecated: Function strcoll() is deprecated since 8.6, use Collator::compare() instead
Deprecated: Function strcoll() is deprecated since 8.6, use Collator::compare() instead
int(-1)
PHP Deprecated: Constant SORT_LOCALE_STRING is deprecated since 8.6, use one of the Collator::*sort*() methods instead
Deprecated: Constant SORT_LOCALE_STRING is deprecated since 8.6, use one of the Collator::*sort*() methods instead
array(3) {
[0]=>
string(5) "Apple"
[1]=>
string(6) "banana"
[2]=>
string(6) "cherry"
}
PHP version change
This behavior was deprecated in 8.6.
This behavior changed in .
See Also
Error Messages
- Function strcoll() is deprecated since 8.6, use Collator::compare() instead
- Constant SORT_LOCALE_STRING is deprecated since 8.6, use one of the Collator::sort() methods instead