From:             
Operating system: CentOS
PHP version:      5.3.8
Package:          JSON related
Bug Type:         Bug
Bug description:json_encode with JSON_NUMERIC_CHECK fails on objects with 
numeric string props

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 bug report at https://bugs.php.net/bug.php?id=55543&edit=1
-- 
Try a snapshot (PHP 5.4):            
https://bugs.php.net/fix.php?id=55543&r=trysnapshot54
Try a snapshot (PHP 5.3):            
https://bugs.php.net/fix.php?id=55543&r=trysnapshot53
Try a snapshot (trunk):              
https://bugs.php.net/fix.php?id=55543&r=trysnapshottrunk
Fixed in SVN:                        
https://bugs.php.net/fix.php?id=55543&r=fixed
Fixed in SVN and need be documented: 
https://bugs.php.net/fix.php?id=55543&r=needdocs
Fixed in release:                    
https://bugs.php.net/fix.php?id=55543&r=alreadyfixed
Need backtrace:                      
https://bugs.php.net/fix.php?id=55543&r=needtrace
Need Reproduce Script:               
https://bugs.php.net/fix.php?id=55543&r=needscript
Try newer version:                   
https://bugs.php.net/fix.php?id=55543&r=oldversion
Not developer issue:                 
https://bugs.php.net/fix.php?id=55543&r=support
Expected behavior:                   
https://bugs.php.net/fix.php?id=55543&r=notwrong
Not enough info:                     
https://bugs.php.net/fix.php?id=55543&r=notenoughinfo
Submitted twice:                     
https://bugs.php.net/fix.php?id=55543&r=submittedtwice
register_globals:                    
https://bugs.php.net/fix.php?id=55543&r=globals
PHP 4 support discontinued:          
https://bugs.php.net/fix.php?id=55543&r=php4
Daylight Savings:                    https://bugs.php.net/fix.php?id=55543&r=dst
IIS Stability:                       
https://bugs.php.net/fix.php?id=55543&r=isapi
Install GNU Sed:                     
https://bugs.php.net/fix.php?id=55543&r=gnused
Floating point limitations:          
https://bugs.php.net/fix.php?id=55543&r=float
No Zend Extensions:                  
https://bugs.php.net/fix.php?id=55543&r=nozend
MySQL Configuration Error:           
https://bugs.php.net/fix.php?id=55543&r=mysqlcfg

Reply via email to