Edit report at https://bugs.php.net/bug.php?id=55543&edit=1
ID: 55543 Updated by: il...@php.net Reported by: dchurch at sciencelogic dot com Summary: json_encode with JSON_NUMERIC_CHECK fails on objects with numeric string props -Status: Open +Status: Closed Type: Bug Package: JSON related Operating System: CentOS PHP Version: 5.3.8 -Assigned To: +Assigned To: iliaa Block user comment: N Private report: N New Comment: 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. Previous Comments: ------------------------------------------------------------------------ [2011-10-17 23:51:25] il...@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-08-31 01:22:17] 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} ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=55543&edit=1