|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #78786 json_encode should have an option to disallow objects
Submitted: 2019-11-06 09:25 UTC Modified: 2019-11-06 13:14 UTC
Avg. Score:4.2 ± 0.8
Reproduced:3 of 4 (75.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: andre at webkr dot de Assigned:
Status: Open Package: JSON related
PHP Version: 7.3.11 OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Bug Type:
From: andre at webkr dot de
New email:
PHP Version: OS:


 [2019-11-06 09:25 UTC] andre at webkr dot de
json_encode() encodes an object by treating its public properties like an array.

This is not always the desired behavior and it's difficult to detect beforehand without walking the whole input array.

Therefore it would be good if json_encode() had an option to make it refuse to encode any object (throw an exception), unless the object implements JsonSerializable.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-06 13:14 UTC]
-Package: Unknown/Other Function +Package: JSON related
 [2019-11-13 19:23 UTC] henry dot paradiz at gmail dot com
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun May 16 04:01:23 2021 UTC