Doc #67599 [Nab]: case mismatch for json_encode between doc and reality
| From: | om+bugs dot php dot net at miakinen dot net | Date: | Thu, 10 Jul 2014 09:30:57 +0000 |
| Subject: | Doc #67599 [Nab]: case mismatch for json_encode between doc and reality | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-11364@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=67599&edit=1
ID: 67599
User updated by: om+bugs dot php dot net at miakinen dot net
Reported by: om+bugs dot php dot net at miakinen dot net
Summary: case mismatch for json_encode between doc and
reality
Status: Not a bug
Type: Documentation Problem
Package: Documentation problem
Operating System: Ubuntu 12.04 (not important)
PHP Version: 5.4.30
Assigned To: sobak
Block user comment: N
Private report: N
New Comment:
Ok, and thank you!
Previous Comments:
------------------------------------------------------------------------
[2014-07-10 09:16:30] sobak@php.net
It probably needs futher clarification. I'll try to expand this example to show behavior
you've described.
------------------------------------------------------------------------
[2014-07-10 08:28:39] om+bugs dot php dot net at miakinen dot net
I'm sorry, it is in fact a bug in the program and not in the documentation.
You are right that < and > are encoded in upper case, but they are the only ones that behave
so !
See that program :
<?php
$json_string = '{
"ctrl1" : "\\u000B\\u000E\\u000F",
"ctrl2" : "\\u001B\\u001C\\u001D\\u001E\\u001F",
"other" : "<> élève grâce à å京"
}';
$json_value = json_decode($json_string);
$json_string2= json_encode($json_value, JSON_HEX_TAG | JSON_PRETTY_PRINT);
echo var_dump($json_string2);
?>
The display is :
string(160) "{
"ctrl1": "\u000b\u000e\u000f",
"ctrl2": "\u001b\u001c\u001d\u001e\u001f",
"other": "\u003C\u003E \u00e9l\u00e8ve gr\u00e2ce \u00e0 \u5317\u4eac"
}"
As you can see, the control characters are \u000b to \u001f, the French accented letters are \u00e0
to \u00e9, and the second chinese character is \u4eac, all in lower case. Only < and > are
\u003C and \u003E in upper case.
Note: In JavaScript, the JSON.stringify function also encodes the control characters in lower case;
I don't know how to obtain hexadecimal code for characters above \u001f.
------------------------------------------------------------------------
[2014-07-10 07:23:53] sobak@php.net
On 5.5.6 and 5.4.26 which I have currently available, output is the same as in the manual. Could you
provide exact code which gave you result with those characters lowercased?
------------------------------------------------------------------------
[2014-07-09 20:44:50] om+bugs dot php dot net at miakinen dot net
Description:
------------
---
From manual page: http://www.php.net/function.json-encode
---
<cit.>
Example #2 A json_encode() example showing some options in use
...
echo "Tags: ", json_encode($a, JSON_HEX_TAG), "\n";
...
The above example will output:
...
Tags:
["\u003Cfoo\u003E","'bar'","\"baz\"","&blong&","\u00e9"]
</cit.>
Actually, it won't output \u003C and \u003E (upper case) but
\u003c and \u003e (lower case).
Note that the same bug exists in French, and probably also in
other languages.
Test script:
---------------
The test script is the one given in the documentation.
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=67599&edit=1