ID:               45162
 Updated by:       [EMAIL PROTECTED]
 Reported By:      christopher dot nagle at umb dot edu
-Status:           Open
+Status:           Bogus
 Bug Type:         JSON related
 Operating System: Windows XP/ Ubuntu
 PHP Version:      5.2.6
 New Comment:

This is totally expected behaviour. Please read this:
http://www.json.org/

Note: array and assoc-array are different things. Latter being "object"
in json.


Previous Comments:
------------------------------------------------------------------------

[2008-06-03 15:35:39] christopher dot nagle at umb dot edu

Description:
------------
After manipulating arrays using [] or creating an array in the form
array("key" => value, ...) or calling unset on an array element.
json_encode will encode the array as an object rather than an array.

Reproduce code:
---------------
echo json_encode(array(1 => new stdClass(), 2 => new stdClass(), 3 =>
new stdClass()));
$m = array();
$m[1] = new stdClass();
$m[2] = new stdClass();
$m[3] = new stdClass();
echo json_encode($m);
$m = array_values($m);
echo json_encode($m);
unset($m[0]);
echo json_encode((array) $m);


Expected result:
----------------
["1":{},"2":{},"3":{}]
["1":{},"2":{},"3":{}]
[{},{},{}]
["1":{},"2":{}]

Actual result:
--------------
{"1":{},"2":{},"3":{}}
{"1":{},"2":{},"3":{}}
[{},{},{}]
{"1":{},"2":{}}


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=45162&edit=1

Reply via email to