php function json_encode different between verion 5.3X and 5.1.6
I find that json_encode in php version 5.1.6 will not return empty key
for example
var_dump(json_encode(array(""=>"value")));
var_dump(json_encode(array(""=>"value1", "key2"=>"value2")));
Expected result:
string(15) "{"":"value"}"
string(17) "{"":"value1", "key2":"value2"}"
Actual result:
string(2) "{}"
string(17) "{"key2":"value2"}"
however in 5.3X
Actual result:
string(15) "{"":"value"}"
string(17) "{"":"value1", "key2":"value2"}"
My question is beside above effect any other difference on json_encode between php 5.3x and 5.1.6
The function json_encode
Docs is part of PHP since version 5.2.0. If you take a look into the manual you will notice a section called Changelog. It documents that the function changed over time and that flags have been introduced to control the json string output.
It's highly likely that the output has changed over time as well and you might need to use additional parameters to better control the expected behavior. Additionally there are some undocumented flags for that function as well.
If you really need to learn about each differences for the output, you need to finally look into the source-code of that function according to version. It's written in C. PHP is open source software, which means, there is nothing hidden, so you can check about any change between versions.
There is no json_encode in PHP before 5.2.1.
You could write you own as a failover:
if (!function_exists('json_encode')) {
function json_encode($data)
{
// your code that parses to json
}
}
精彩评论