|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55354 Incorrect typecasting of keys in json_encode w/ JSON_NUMERIC_CHECK set
Submitted: 2011-08-03 11:31 UTC Modified: 2011-08-04 13:23 UTC
From: rick dot van dot ravensberg at tribal-im dot com Assigned: iliaa (profile)
Status: Not a bug Package: JSON related
PHP Version: 5.3.6 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
24 + 28 = ?
Subscribe to this entry?

 [2011-08-03 11:31 UTC] rick dot van dot ravensberg at tribal-im dot com
When using json_encode with JSON_NUMERIC_CHECK, json_encode still converts all 
array keys to a string, instead of keeping integer keys as integer. However, the 
JSON_NUMERIC_CHECK option does work correctly on all the array values.

Test script:
$array = array (
	1	=> "foo",
	5	=> "bar",
	"10"	=> 50,

echo json_encode ($array, JSON_NUMERIC_CHECK);

Expected result:

Actual result:


LoL (last revision 2011-08-04 00:59 UTC by fkkkkkkkkkkk at hotmail dot com)

Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-08-03 23:21 UTC]
-Status: Open +Status: Assigned -Assigned To: +Assigned To: iliaa
 [2011-08-03 23:21 UTC]
The JSON_NUMERIC_CHECK is supposed to work in the value, not the key.

Is it right, @Ilia?
 [2011-08-04 13:23 UTC]
-Status: Assigned +Status: Bogus
 [2011-08-04 13:23 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

The numeric check only works on values.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed May 29 19:01:32 2024 UTC