php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #55543 json_encode with JSON_NUMERIC_CHECK fails on objects with numeric string props
Submitted: 2011-08-31 01:22 UTC Modified: 2011-10-17 23:51 UTC
From: dchurch at sciencelogic dot com Assigned: iliaa (profile)
Status: Closed Package: JSON related
PHP Version: 5.3.8 OS: CentOS
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: dchurch at sciencelogic dot com
New email:
PHP Version: OS:

 

 [2011-08-31 01:22 UTC] dchurch at sciencelogic dot com
Description:
------------
When JSON_NUMERIC_CHECK is used with json_encode, it looks at every string that is printed, including for property names, and checks whether to display it as an integer instead.  However, JSON mandates that all property names be represented as double-quoted strings, and displaying them as integers violates the spec.

The attached patch (against the php-5.3.8 tarball, should apply cleanly against SVN 5.3 branch) fixes this by masking out the JSON_NUMERIC_CHECK flag while outputting string properties.

Test script:
---------------
$output = (object)array();
$output->{"1"} = "5";
echo json_encode($output, JSON_NUMERIC_CHECK);


Expected result:
----------------
{"1":5}

Actual result:
--------------
{1:5}

Patches

php-5.3.8-json_numeric_check-fix.patch (last revision 2011-08-31 01:23 UTC by dchurch at sciencelogic dot com)

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-10-17 23:51 UTC] iliaa@php.net
Automatic comment from SVN on behalf of iliaa
Revision: http://svn.php.net/viewvc/?view=revision&revision=318178
Log: Fixed bug #55543 (json_encode() with JSON_NUMERIC_CHECK fails on objects with numeric string properties)
 [2011-10-17 23:51 UTC] iliaa@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: iliaa
 [2011-10-17 23:51 UTC] iliaa@php.net
This bug has been fixed in SVN.

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/.

 For Windows:

http://windows.php.net/snapshots/
 
Thank you for the report, and for helping us make PHP better.


 [2012-04-18 09:48 UTC] laruence@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=65732af7da2a32bf43c1a0918a6725c4c333182d
Log: Fixed bug #55543 (json_encode() with JSON_NUMERIC_CHECK fails on objects with numeric string properties)
 [2012-07-24 23:39 UTC] rasmus@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=65732af7da2a32bf43c1a0918a6725c4c333182d
Log: Fixed bug #55543 (json_encode() with JSON_NUMERIC_CHECK fails on objects with numeric string properties)
 [2013-11-17 09:35 UTC] laruence@php.net
Automatic comment on behalf of iliaa
Revision: http://git.php.net/?p=php-src.git;a=commit;h=65732af7da2a32bf43c1a0918a6725c4c333182d
Log: Fixed bug #55543 (json_encode() with JSON_NUMERIC_CHECK fails on objects with numeric string properties)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Nov 21 11:01:29 2024 UTC