Created
April 16, 2013 14:11
-
-
Save mattieb/5396214 to your computer and use it in GitHub Desktop.
Why PHP sucks, volume 295: how array stupidity breaks json_encode
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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)); |
Submit a report?
"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."
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
And don't even get me started on how upgrade.php's json_encode makes this bad situation even worse.