php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53291 json_encode throws away array elements with an empty string for a key
Submitted: 2010-11-10 16:42 UTC Modified: 2010-11-10 21:15 UTC
From: pwinnski at gmail dot com Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.14 OS: Linux
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: pwinnski at gmail dot com
New email:
PHP Version: OS:

 

 [2010-11-10 16:42 UTC] pwinnski at gmail dot com
Description:
------------
In 5.2.14, json_encode() silently discards any array values for which the array 
key is an empty string. This seems identical to Bug #41505, but affects PHP 
5.2.14.

Demonstration code:
var_dump(json_encode(array("" => array("a" => 1))));

Expect (result in 5.2.6, 5.2.10, 5.2.13, 5.3.2):
string(12) "{"":{"a":1}}"

Receive (in 5.2.14):
string(2) "{}"

Test script:
---------------
var_dump(json_encode(array("" => array("a" => 1))));

Expected result:
----------------
string(12) "{"":{"a":1}}"

Actual result:
--------------
string(2) "{}"

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-10 21:15 UTC] cataphract@php.net
-Status: Open +Status: Bogus
 [2010-11-10 21:15 UTC] cataphract@php.net
I can't reproduce this in PHP 5.2.14:

root@router:~# php -v
PHP 5.2.14 (cli) (built: Aug 18 2010 17:16:15)
Copyright (c) 1997-2010 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2010 Zend Technologies
root@router:~# php
<?php
dl("json.so");
var_dump(json_encode(array("" => array("a" => 1))));
string(12) "{"":{"a":1}}"

But even if there was actually a bug, PHP 5.2 is only to receive security updates at this point. So Bogus/Wont Fix.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sun Jan 26 08:01:24 2020 UTC