Bug #77347 [Opn]: switch casting behavior by setlocale(LC_NUMERIC, '') is wrong

From: Date: Wed, 26 Dec 2018 14:35:09 +0000
Subject: Bug #77347 [Opn]: switch casting behavior by setlocale(LC_NUMERIC, '') is wrong
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218621@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77347&edit=1 ID: 77347 User updated by: spam2 at rhsoft dot net Reported by: spam2 at rhsoft dot net -Summary: switch catsing behavior by setlocale(LC_NUMERIC, '') is wrong +Summary: switch casting behavior by setlocale(LC_NUMERIC, '') is wrong Status: Open Type: Bug Package: Scripting Engine problem Operating System: Linux PHP Version: 7.2.13 Block user comment: N Private report: N New Comment: fixed typo in summary Previous Comments: ------------------------------------------------------------------------ [2018-12-26 14:32:13] spam2 at rhsoft dot net Description: ------------ you can disable comments for https://bugs.php.net/bug.php?id=77278 as much as you want - the current behavior of the scriptiung language is plain wrong and this seems have to be fixed even in the past looking at https://bugs.php.net/bug.php?id=17815 and "Workaround for this bug: setlocale(LC_NUMERIC,'C');" * LC_NUMERIC="de_DE.UTF-8" is the default environment here * if you call the changing behavior depending on locale correct you mustn't silently change it to LC_NUMERIC=C to begin with and that code sample would always come with , instead . * but it does not * it does only after a random setlocale wihtin PHP or some library [harry@srv-rhsoft:/downloads]$ locale LANG=de_DE.UTF-8 LC_CTYPE="de_DE.UTF-8" LC_NUMERIC="de_DE.UTF-8" LC_TIME="de_DE.UTF-8" LC_COLLATE="de_DE.UTF-8" LC_MONETARY="de_DE.UTF-8" LC_MESSAGES="de_DE.UTF-8" LC_PAPER="de_DE.UTF-8" LC_NAME="de_DE.UTF-8" LC_ADDRESS="de_DE.UTF-8" LC_TELEPHONE="de_DE.UTF-8" LC_MEASUREMENT="de_DE.UTF-8" LC_IDENTIFICATION="de_DE.UTF-8" LC_ALL= [harry@srv-rhsoft:/downloads]$ php /downloads/casting.php LC_CTYPE=de_DE.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 OK: 4 de_DE.UTF-8 FAIL: 3,3333333333333 Test script: --------------- [harry@srv-rhsoft:/downloads]$ cat /downloads/casting.php <?php declare(strict_types=1); echo setlocale(LC_ALL, '0'), "\n"; $pages_summary = (string)(10 / 3); if($pages_summary > (int)$pages_summary) { $pages_summary = (int)$pages_summary + 1; } if((int)$pages_summary !== 4) { echo "FAIL: $pages_summary\n"; } else { echo "OK: $pages_summary\n"; } echo "\n"; echo setlocale(LC_NUMERIC, ''), "\n"; $pages_summary = (string)(10 / 3); if($pages_summary > (int)$pages_summary) { $pages_summary = (int)$pages_summary + 1; } if((int)$pages_summary !== 4) { echo "FAIL: $pages_summary\n"; } else { echo "OK: $pages_summary\n"; } Expected result: ---------------- no change in casting behavior Actual result: -------------- don't change internal behavior randomly ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77347&edit=1

« previous php.bugs (#218621) next »