setlocale

FunctionParams and return types changed in PHP 8.0

Set locale information.

PHP 5
PHP 7
PHP 8.0
Improved
PHP 8.1
PHP 8.2-8.3
PHP 8.4
PHP 8.5
PHP 8.6

setlocale Function synopsis

setlocale(
    int $category,
    $locales,
    ...$rest
  ): string|false

Parameters

$category

Typeint

$category is a named constant specifying the category of the functions affected by the locale setting:

$locales

If $locales is the empty string "" or is null, the locale names will be set from the values of environment variables with the same names as the above categories, or from "LANG".

$rest

Variadic, Optional

Optional string parameters to try as locale settings until success.

Return value

Typestring|false

Returns the new current locale, or false if the locale functionality is not implemented on your platform, the specified locale does not exist or the category name is invalid.

An invalid category name also causes a warning message. Category/locale names can be found in RFC 1766 and ISO 639. Different systems have different naming schemes for locales.

The return value of [`setlocale`](/codex/setlocale) depends
on the system that PHP is running.  It returns exactly
what the system `setlocale` function returns.

Changes to the setlocale Function

PHP 8.0

  • Return type added: string|false
  • Optional parameter added - #3: $rest
-setlocale($category, ...$locales)
+setlocale(
+    int $category,
+    $locales,
+    ...$rest
+  ): string|false

setlocale Function Availability

PHP VersionAvailability
PHP 8.6Upcoming Release Yes
PHP 8.5Supported (Latest) Yes
PHP 8.4Supported Yes
PHP 8.3Security-Fixes Only Yes
PHP 8.2Security-Fixes Only Yes
PHP 8.1Unsupported Yes
PHP 8.0Unsupported Yes
PHP 7.4Unsupported Yes
PHP 7.3Unsupported Yes
PHP 7.2Unsupported Yes
PHP 7.1Unsupported Yes
PHP 7.0Unsupported Yes
PHP 5.6Unsupported Yes
PHP 5.5Unsupported Yes
PHP 5.4Unsupported Yes
PHP 5.3Unsupported Yes