Lets begin with two small tests:
$original = [0 => 'a', 1 => 'b'];
var_dump((json_decode(json_encode($original))));
returns
array(2) { // array
[0]=> // integer like original
string(1) "a"
[1]=> // integer like original
string(1) "b"
}
So we can see here, that assoc parameter (second parameter in json_decode function) is not set (default is false), and pair json_decode-json_encode recovers original as it should.
$original = [1 => 'a', 2 => 'b'];
var_dump((json_decode(json_encode($original))));
returns
object(stdClass)#1 (2) { // object
["1"]=> // string, instead of integer
string(1) "a"
["2"]=> // string, instead of integer
string(1) "b"
}
Here again, assoc is false, but pair json_decode-json_encode can't recover original unless we explicitly set assoc into true.
Question: I am working on a custom serialization process (different from PHP serialize and unserialize functions). I decided to use json_decode-json_encode pair and I found that I can't rely on default settings, like assoc=false. Are you aware of any other pitfalls with json_ family functions that may lead me to a problem when I won't be able to recover original data and structure?