#42785 [Asn->Csd]: json_encode output numbers formatted according to the locales instead of std
| From: | iliaa@php.net | Date: | Mon, 01 Oct 2007 15:33:37 +0000 |
| Subject: | #42785 [Asn->Csd]: json_encode output numbers formatted according to the locales instead of std | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-118025@lists.php.net to get a copy of this message | ||
ID: 42785
Updated by: iliaa@php.net
Reported By: gebura at evilkittens dot org
-Status: Assigned
+Status: Closed
Bug Type: JSON related
Operating System: Linux / Unix
PHP Version: 5.2.4
Assigned To: iliaa
New Comment:
This bug has been fixed in CVS.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2007-09-28 09:32:08] gebura at evilkittens dot org
Description:
------------
json_encode() output numbers formated according the to locales instead
of standard format.
For example, in french coma is used for separate decimals. (like 1,5)
But in json:
- numbers must use a point for separate decimals (like 1.5)
- coma is used as field separator. (like "a","b")
So the result is not correct.
This bug is related with Bug #40360 ('current locale affects how
json_encode encodes floats') witch is closed.
Reproduce code:
---------------
<?php
if (setlocale(LC_ALL,"fr_FR.UTF-8") != "fr_FR.UTF-8")
{
die("Could not change the locale!");
}
$foo = Array(100.10,"bar");
echo json_encode($foo);
Class bar {}
$bar1 = new bar;
$bar1->a = 100.10;
$bar1->b = "foo";
echo json_encode($bar1);
?>
Expected result:
----------------
[100.1,"bar"]{"a":100.1,"b":"foo"}
Actual result:
--------------
[100,1,"bar"] // 2 fields => 3 fields
{"a":100,1,"b":"foo"} // the output couldn't be evaluated
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=42785&edit=1