note 119340 deleted from function.json-encode by cmb
| From: | cmb@php.net | Date: | Tue, 17 May 2016 11:58:00 +0000 |
| Subject: | note 119340 deleted from function.json-encode by cmb | ||
| References: | 1 | Groups: | php.notes |
| Request: | Send a blank email to php-notes+get-205500@lists.php.net to get a copy of this message | ||
Note Submitter: chris at fuelforthefire dot ca
----
echo json_encode(array('0' => 'Zero', '2' => 'Two'));
> {'0' => 'Zero', '2' => 'Two'}
echo json_encode(array('1' => 'One', '2' => 'Two'));
> {'1' => 'One', '2' => 'Two'}
echo json_encode(array('0' => 'Zero', '1' => 'One',
'2' => 'Two'));
> ['Zero', 'One', 'Two']
Whoever decided this default behaviour made sense really must hate programmers. The logic should
either work one or not, you can't pick and choose when something should happen, otherwise how
can you make generic code? How am I supposed to tell someone using my communication protocol,
"Hey, don't use anything that might look like an array cause PHP will break it?"
This needs to be fixed.