Closed mihai-stancu closed 9 years ago
thanks, when I wrote this code I did not want have useless IF, but your variant is more clear.
If you expect to use this code PHPEncode => UBJSON => JSDecode then there is indeed no problem because arrays in JS will be reindexed when you decode it.
But if you expect to use this code PHPEncode => UBJSON => PHPDecode then there will be differences between the original encoded value and the decoded value.
I was writing a unit test for a bundle that uses PHP Encode/Decode with UBJSON and noticed the difference that way :).
In the original code the
$key
starts from0
but is incremented inside the loop before being used.Because of this an originally zero-indexed array would have (incorrectly) always started from an index of
1
.This patch fixes the problem.