|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2014-12-04 16:37 UTC] j dot tvr at centrum dot cz
Description:
------------
Calling json_decode may result in fatal error.
Test script:
---------------
json_decode('{"\u0000": 1}');
Expected result:
----------------
It should not result in fatal error.
Patchesjson-0 (last revision 2015-05-28 00:54 UTC by cmb@php.net)Pull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Oct 29 06:00:01 2025 UTC |
*That* code works fine. $obj->{"\x00"} won't, which I assume is what you're actually trying to report. If you think your keys may have control characters, or in general characters not valid for property/variable names, then decode to an array instead. Just because JSON supports certain object keys doesn't mean PHP should too.<?php var_dump(json_decode('{"a": 1}')); var_dump(json_decode('{"1": 1}')); var_dump(json_decode('{a: 1, "a": 1}')); // invalid JSON var_dump(json_decode('{"a\u0000b: 1}')); // invalid JSON ?> http://3v4l.org/nncBo E_WARNING may be too much. Just returning NULL seems to be enough and leave users to handle errors.