|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50166 json_encode returns wrong brackets for empty array
Submitted: 2009-11-13 13:59 UTC Modified: 2009-11-13 14:56 UTC
Avg. Score:1.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: dumpbox at mail dot ru Assigned:
Status: Not a bug Package: JSON related
PHP Version: 5.2.11 OS: Windows XP
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.
Block user comment
Status: Assign to:
Bug Type:
From: dumpbox at mail dot ru
New email:
PHP Version: OS:


 [2009-11-13 13:59 UTC] dumpbox at mail dot ru
By default json object starts with "{" and ends with "}"
Error occurs when user attempt encode empty array.

Reproduce code:
echo json_encode(array());

Expected result:

Actual result:


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-13 14:56 UTC]
Yes, that would be an array in JSON. Please check for the syntax. No bug here. (and yes, assoc arrays do end up as objects..)

Like this:

[jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo" => "bar")));'
string(13) "{"foo":"bar"}"
[jani@localhost ~]$ php -r 'var_dump(json_encode(array("foo", "bar")));'
string(13) "["foo","bar"]"

No bug here.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sun Apr 14 15:01:29 2024 UTC