Skip to content

setlocale($type, NULL) should not be deprecated #19070

Closed

Description

@remicollet

Description

Since 43c18f3

A simple setlocale(LC_ALL, NULL) raise a deprecation

This is the common way to retrieve the current locale (else we need a getlocale function)

From the setlocale unix man page

   If locale is NULL, the current locale is only queried, not modified.

Can you please consider removing this change

Ex: m6w6/ext-http#148

PHP Version

PHP 8.5.0alpha1

Operating System

No response

Activity

  1. remicollet commented on Jul 8, 2025

    @remicollet
    MemberAuthor

    ping @nielsdos as the author of the change

  2. changed the title [-]setlocale($type, NULL) shoud not be deprecated[/-] [+]setlocale($type, NULL) should not be deprecated[/+] on Jul 8, 2025
  3. remicollet commented on Jul 8, 2025

    @remicollet
    MemberAuthor

    Notice: our documentation is confusing

    If locales is "0", the locale setting is not affected, only the current setting is returned.

    $ php -r 'var_dump(setlocale(LC_ALL, null));'
    string(11) "fr_FR.UTF-8"
    
    $ php -r 'var_dump(setlocale(LC_ALL, 0));'
    string(166) "LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
    
    $ php -r 'var_dump(setlocale(LC_ALL, "0"));'
    string(166) "LC_CTYPE=C.UTF-8;LC_NUMERIC=C;LC_TIME=C;LC_COLLATE=C;LC_MONETARY=C;LC_MESSAGES=C;LC_PAPER=C;LC_NAME=C;LC_ADDRESS=C;LC_TELEPHONE=C;LC_MEASUREMENT=C;LC_IDENTIFICATION=C"
    

    Only null returns the current setting.

  4. remicollet commented on Jul 8, 2025

    @remicollet
    MemberAuthor

    Also see documentation update proposal in https://github.com/php/doc-en/pull/4765/files

  5. self-assigned this
    on Jul 8, 2025
  6. ndossche commented on Jul 8, 2025

    @ndossche
    Member

    Unintentional break! I'll go fix it. It should indeed accept NULL.

  7. added a commit that references this issue on Jul 8, 2025
    e004c22
  8. added a commit that references this issue on Jul 10, 2025
    c4183fb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions