php.net |  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
Votes:4
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
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
13 + 3 = ?
Subscribe to this entry?

 
 [2019-11-06 09:25 UTC] andre at webkr dot de
Description:
------------
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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-11-06 13:14 UTC] cmb@php.net
-Package: Unknown/Other Function +Package: JSON related
 [2019-11-13 19:23 UTC] henry dot paradiz at gmail dot com
Agreed.
 [2023-06-02 10:07 UTC] hydtwuegiu32 at gmail dot com
I need that type of things.(https://www.ballsportspro.com/)github.com
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon Dec 02 14:01:29 2024 UTC