php.net |  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 Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: rick dot van dot ravensberg at tribal-im dot com
New email:
PHP Version: OS:

 

 [2011-08-03 11:31 UTC] rick dot van dot ravensberg at tribal-im dot com
Description:
------------
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:
---------------
<?php
$array = array (
	1	=> "foo",
	5	=> "bar",
	"10"	=> 50,
);

echo json_encode ($array, JSON_NUMERIC_CHECK);
?>

Expected result:
----------------
{1:"foo",5:"bar","10":50}

Actual result:
--------------
{"1":"foo","5":"bar","10":50}

Patches

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

Pull Requests

History

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

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

The numeric check only works on values.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 13:01:31 2024 UTC