Bug #77278 [Ver]: floatval(strval(value)) truncates if locale's decimal_point isn't a period

From: Date: Mon, 10 Dec 2018 22:16:59 +0000
Subject: Bug #77278 [Ver]: floatval(strval(value)) truncates if locale's decimal_point isn't a period
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218385@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77278&edit=1 ID: 77278 Updated by: requinix@php.net Reported by: spam2 at rhsoft dot net Summary: floatval(strval(value)) truncates if locale's decimal_point isn't a period Status: Verified Type: Bug Package: Scripting Engine problem PHP Version: Irrelevant Block user comment: Y Private report: N New Comment: spam2, there's two bugs here: 1. PHP converts by locale in one direction (float->string) but not in the other direction (string->float). It should be consistent. But like @nikic said, this inconsistency is currently the intended behavior - not the correct behavior, merely the *intended* behavior. It does need to get fixed but it's not a simple thing to just do. 2. Tidy changes locales for whatever reason. Okay. But it does not change the locale back to the original value when it is done, and that is not okay. It needs to change it back in case the calling code had set a locale and still needs it. That is just basic etiquette for any library code. This is a bug Tidy needs to fix, not PHP. Getting the locale is possible by passing null to setlocale. You probably aren't seeing en_US because you don't have the locale installed, and calling setlocale with it would have returned false. Do locale -a to see what you have available. Previous Comments: ------------------------------------------------------------------------ [2018-12-10 21:59:50] nikic@php.net Please calm down. ------------------------------------------------------------------------ [2018-12-10 21:52:37] spam2 at rhsoft dot net ok, you can partially repdoduce that behavior echo (string)4/3, "\n"; setlocale(LC_ALL, 'en_US.UTF-8'); echo (string)4/3, "\n"; setlocale(LC_ALL, 'de_DE.UTF-8'); echo (string)4/3, "\n"; ------------------------------- BUT YOU CANN NOT GET THE CURRECT LOCALE WITH PHP echo (string)4/3, "\n"; setlocale(LC_ALL, 'en_US.UTF-8'); echo setlocale(LC_ALL, NULL), "\n"; echo (string)4/3, "\n"; setlocale(LC_ALL, 'de_DE.UTF-8'); echo setlocale(LC_ALL, NULL), "\n"; echo (string)4/3, "\n"; [harry@srv-rhsoft:/downloads]$ php test.php 1.3333333333333 de_DE.UTF-8 1,3333333333333 de_DE.UTF-8 1,3333333333333 ------------------------------- why don't that shit mention 'en_US.UTF-8' which i would have liked to put at the libtidy bugreport instead wasting all my time with assumptions? there is anyways no sibgle pojnt of have TYPECASTS behave different - that's what format functions are! ------------------------------------------------------------------------ [2018-12-10 21:45:13] spam2 at rhsoft dot net nonsense! show me the PHP code where type casts after setlocale() change tehir meaning! you can't even distinct what happens by use setlocale('whatever', NULL) before and after the tidy call because i get always get de_DE.UTF-8 as result ------------------------------------------------------------------------ [2018-12-10 21:41:36] requinix@php.net You can't blame PHP for Tidy's problem. If they change locale (already a dangerous operation since it's not thread-safe) and then don't revert it to the previous setting when they're done, that's their fault. ------------------------------------------------------------------------ [2018-12-10 21:33:13] spam2 at rhsoft dot net working as intended? a random linked library calls locale and the whole behavior of internal php typecast changes for every follow-up code in a PHP application is intended? really? ------------------------------------------------------------------------ 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=77278 -- Edit this bug report at https://bugs.php.net/bug.php?id=77278&edit=1

« previous php.bugs (#218385) next »