strcoll() Function use in PHP 8.4 and PHP 8.5

strcoll() is fully supported in PHP 8.4, but it is deprecated starting from PHP 8.6. So for PHP 8.5, it is still available and functional, but you should be aware that its removal is on the horizon.

Example & Recommended Alternative

Using strcoll() (Works in 8.4/8.5, Deprecated in 8.6):

<?php
setlocale(LC_COLLATE, de_DE );
$a = "Österreich";
$b = "Oesterreich";

// Output depends on the locale and platform
var_dump(strcoll($a, $b)); 
?>

The Recommended Way (Using Collator):

<?php
// Requires the intl extension
$collator = new Collator( de_DE );
$a = "Österreich";
$b = "Oesterreich";

// Returns 1 (correctly ranks "Ö" after "Oe" in German)
var_dump($collator->compare($a, $b)); 
?>

Summary: You can use strcoll() safely in PHP 8.4 and 8.5 without errors, but for future-proof code, it is best to switch to Collator::compare().


 

9 Views