|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #42785 json_encode output numbers formatted according to the locales instead of std
Submitted: 2007-09-28 09:32 UTC Modified: 2007-10-01 15:33 UTC
Avg. Score:4.3 ± 0.7
Reproduced:6 of 6 (100.0%)
Same Version:5 (83.3%)
Same OS:4 (66.7%)
From: gebura at evilkittens dot org Assigned: iliaa (profile)
Status: Closed Package: JSON related
PHP Version: 5.2.4 OS: Linux / Unix
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: gebura at evilkittens dot org
New email:
PHP Version: OS:


 [2007-09-28 09:32 UTC] gebura at evilkittens dot org
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:

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:

Actual result:
[100,1,"bar"] // 2 fields => 3 fields 
{"a":100,1,"b":"foo"} // the output couldn't be evaluated 


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-01 15:33 UTC]
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
Thank you for the report, and for helping us make PHP better.

PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 23 11:01:33 2024 UTC