ID: 38680 Updated by: [EMAIL PROTECTED] Reported By: RQuadling at GMail dot com -Status: Assigned +Status: Closed Bug Type: Unknown/Other Function PHP Version: 5.2 Assigned To: iliaa New Comment:
This bug has been fixed in CVS. Snapshots of the sources are packaged every three hours; this change will be in the next snapshot. You can grab the snapshot at http://snaps.php.net/. Thank you for the report, and for helping us make PHP better. Previous Comments: ------------------------------------------------------------------------ [2006-09-24 18:41:28] [EMAIL PROTECTED] reclassified & assigned to Ilia ------------------------------------------------------------------------ [2006-09-24 00:21:07] [EMAIL PROTECTED] This is a documentation issue that must (should) be resolved before PHP 5.2 is released. The current docs were taken straight out of the README that's within the json extension sources. Please summarize exactly what needs to be changed here. ------------------------------------------------------------------------ [2006-09-04 08:55:41] RQuadling at GMail dot com Why is this bogus? I've reopened it as the PHP Dox makes no mention of the restriction that only objects and arrays are encodable/decodable. And if the json_encode only dealt with arrays & objects rather than all types except resources, then the code would be cleaner and give less issue. ------------------------------------------------------------------------ [2006-09-01 14:43:33] RQuadling at GMail dot com I'm not sure I follow. I'm reading the PHP doc and json_encode says it can encode _ANY_ type except resource. json_decode says it "takes a JSON encoded string and converts it into a PHP variable". So, $m_var = json_decode(json_decode($m_original_var)); $m_var == $m_original_var. Maybe NOT ===, but at least == So, there are several issues here. json_encode says ANY type. Not just objects or arrays. Admittedly, an array with int/bool/null in all work fine as does a multi-dimensional array. If the dox said JUST arrays and objects, then that would be fine too. You could then emit a warning when the types supplied wasn't an array or an object. But, as it stands, the dox say __ANY__, so, it is VERY reasonable to assume that encoding boolean/integers/null via json_encode will produce something usable. AND json_decode says it will decode any json_encoded string. Now, at this stage, I'm not even using the data, I'm just encoding it and then instantly decoding it. Not via a browser or JS. Just all in PHP. And this is not working. In your reply you say that "true/false/null/numerics in raw form are not valid JSON structures, so json_decode will reject them and output NULL" - Fair enough, but not what my bug report is about. I'm saying that json_encode is NOT producing correctly encoded structures for json_decode, NOT that I'm manually creating these structures and expecting them to work. <?php var_dump(json_decode(json_encode(True))); var_dump(json_decode(json_encode(False))); var_dump(json_decode(json_encode(Null))); var_dump(json_decode(json_encode(pi()))); var_dump(json_decode(json_encode(phpversion()))); ?> produces NULL NULL NULL NULL NULL Very much NOT what would be expected! ------------------------------------------------------------------------ [2006-09-01 14:25:21] [EMAIL PROTECTED] Thank you for taking the time to write to us, but this is not a bug. Please double-check the documentation available at http://www.php.net/manual/ and the instructions on how to report a bug at http://bugs.php.net/how-to-report.php This is a documentation issue... true/false/null/numerics in raw form are not valid JSON structures, so json_decode will reject them and output NULL. Basically, if JSON_checker (http://www.json.org/JSON_checker/) says something is invalid JSON, then json_decode will return NULL. json_encode emits true/false/etc as any other way makes even less sense. :) ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/38680 -- Edit this bug report at http://bugs.php.net/?id=38680&edit=1