Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

setlocale() Rejects Extra Arguments When $locales Is An Array

setlocale() accepts either a list of individual locale name arguments, or a single array of candidate locale names as its second parameter. Until PHP 8.6, passing an array as $locales while also passing further variadic locale arguments was silently accepted, and the extra arguments were ignored. In PHP 8.6, passing any additional locale argument alongside an array $locales throws a TypeError.

PHP code

<?php

try {
    var_dump(setlocale(LC_ALL, ['en_US'], 'fr_FR'));
} catch (\TypeError $e) {
    echo "TypeError: ".$e->getMessage()."\n";
}

?>

Before

string(5) "en_US" 

After

TypeError: setlocale() expects exactly 2 arguments when argument #2 ($locales) is an array, 3 given

PHP version change

This behavior changed in 8.6.

See Also

Error Messages

Extension

© 2023-2026, Damien Seguy - Exakat