-
-
Notifications
You must be signed in to change notification settings - Fork 585
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Unexpected results when serializing arrays containing null value elements #593
Milestone
Comments
Is this data on an object or do you just have this array structure? |
Ah, right, didn't mention this. In this case it's just an array structure I'm building myself... |
possible solution #660 (and source of the problem) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi,
I just experienced problems with an unexpected behavior when serializing arrays that contain null value elements, meaning: When one or more elements of the array are set to
null
. Note: I'm not talking about serializing null values at all – I know (need and enabled) this option, but the unexpected behavior affects both scenarios: When serializing null values is enabled as well when it is not.Example to reproduce the behavior (from a SF controller context):
Now, when dumping the
$result
we get this:While the JSON output for
foo
andbar
looks normal, be sure you noticed the vanished null element forbaz
and strangely indexed second array element ofbiz
.This is obviously not a behavior or bug of
json_encode
itself, simply proven when dumping the result ofjson_encode($data)
, which looks much more like what I would expect:Conclusion: Null value elements in arrays somehow get lost but the array itself – if null values were present – gets converted into an "object" with original numeric indices (with holes were the null values originally resided). Pheeew, a bit complicated to describe, you see it for yourself...
I would classify this bug (if not my mistake of any kind!) as severe since it doesn't allow to deal with null values within arrays at all! That's actually part of my current use case – and I'm pretty sure it is not that exotic.
Totally independently of this specific problem I'd like to say: Thanks to the author and all contributors for a very helpful piece of software you're sharing with us!
The text was updated successfully, but these errors were encountered: