Skip to content

Invalid default return value for setlocale() #5562

@nicolas-grekas

Description

@nicolas-grekas

Trying to fetch the default locale returns the empty string, when in fact it should be "C".
Since setting the locale to the empty string changes it to the default of the system (which is not C usually), this makes it impossible to save the current locale, do some stuff, and restore it correctly afterwards.

var_dump(setlocale(LC_NUMERIC, 0));
echo sprintf('%s', 4.3), "\n";

var_dump(setlocale(LC_NUMERIC, ''));
echo sprintf('%s', 4.3), "\n";

echoes:

string(0) ""
4.3
string(0) ""
4,3

Not the comma vs dot in the float to string conversion.

The same script on PHP echoes:

string(1) "C"
4.3
string(11) "fr_FR.UTF-8"
4,3

which is much better.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions