Skip to content

Instantly share code, notes, and snippets.

@zigg

zigg/gist:5396214

Created Apr 16, 2013
Embed
What would you like to do?
Why PHP sucks, volume 295: how array stupidity breaks json_encode
<?php
var_dump(json_encode(array(1, 2, 3)));
var_dump(json_encode(array(0=>1, 1=>2, 2=>3)));
var_dump(json_encode(array(1=>1, 2=>2, 3=>3)));
$a = array(1, 2, 3);
var_dump(json_encode($a));
unset($a[1]);
var_dump(json_encode($a));
@zigg

This comment has been minimized.

Copy link
Owner Author

@zigg zigg commented Apr 16, 2013

And don't even get me started on how upgrade.php's json_encode makes this bad situation even worse.

@jellisii

This comment has been minimized.

Copy link

@jellisii jellisii commented Apr 16, 2013

Submit a report?

@zigg

This comment has been minimized.

Copy link
Owner Author

@zigg zigg commented Apr 16, 2013

"Dear PHP, please redesign your arrays so they do not morph from associative to non-associative and back again based on what the keys are."

@trenton42

This comment has been minimized.

Copy link

@trenton42 trenton42 commented Dec 18, 2013

I can't imagine the number of things that would break if that got fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.