Bug #67127 [Asn]: setlocale LC_NUMERIC breaks DateTime microseconds
Edit report at https://bugs.php.net/bug.php?id=67127&edit=1
ID: 67127
Updated by: cmb@php.net
Reported by: honzap at gmail dot com
Summary: setlocale LC_NUMERIC breaks DateTime microseconds
Status: Assigned
Type: Bug
Package: Date/time related
Operating System: Linux (Debian Wheezy)
PHP Version: 5.4.27
Assigned To: derick
Block user comment: N
Private report: N
New Comment:
> This is related to the problem that double conversion does not
> work with LC_NUMERIC=cs_CZ.utf8 (or some other locale with , as
> decimal point like de_DE.utf8).
To be clear, double to string conversion works as intended for any
locale; it's just not the most sensible behavior[1]. Anyhow, this
bug is not about that issue (see originally supplied test script).
[1] <https://wiki.php.net/rfc/locale_independent_float_to_string>
Previous Comments:
------------------------------------------------------------------------
[2018-04-07 18:38:20] cmb@php.net
Related To: Bug #76190
------------------------------------------------------------------------
[2017-12-11 15:28:14] thflori at gmail dot com
This is related to the problem that double conversion does not work with LC_NUMERIC=cs_CZ.utf8 (or
some other locale with , as decimal point like de_DE.utf8).
Test script:
------------
echo (double)'0.42';
setlocale(LC_NUMERIC, 'de_DE.utf8');
echo (double)'0.42';
Expected Output:
----------------
0.42
0,42
Actual Output:
--------------
0.42
0,42.0
------------------------------------------------------------------------
[2016-08-07 10:09:11] cmb@php.net
Related To: Bug #48225
------------------------------------------------------------------------
[2016-08-07 09:52:22] cmb@php.net
Related To: Bug #47312
------------------------------------------------------------------------
[2016-08-06 18:16:30] cmb@php.net
I can confirm this issue. The culprit is in timelib_get_frac_nr()
where strtod() is used[1], which is locale dependend. Using
zend_strtod() instead would solve the issue, but that would make
timelib depending on the Zend engine, what is certainly not
desired.
Derick, what do you think about including some locale independent
strtod() replacement[2].
@wilfrid Your issue is unrelated to this bug report, and actually,
it is not a bug, but rather being caused by setlocale() not being
thread safe[3]. Consider to use the intl extension[4] instead.
[1] <https://github.com/derickr/timelib/blob/master/parse_date.re#L514>
[2] fe. <http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8/missing/strtod.c>
[3] <http://php.net/manual/en/function.setlocale.php#refsect1-function.setlocale-notes>
[4] <http://php.net/manual/en/intro.intl.php>
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=67127
--
Edit this bug report at https://bugs.php.net/bug.php?id=67127&edit=1
Thread (7 messages)