Jason Webster wrote:
Matthew Weier O'Phinney wrote:
-- Christoph Dorn <[EMAIL PROTECTED]> wrote
(on Thursday, 04 September 2008, 10:54 AM -0700):
It is an issue with Zend_Json_Encoder.
The problem is that JSON does not support associative arrays. See
ticket
http://framework.zend.com/issues/browse/ZF-4159
Actually, that's not entirely true. PHP associative arrays translate
basically to JS objects. The problem occurs when PHP needs to encode an
array -- is an array with numeric indices an associative or normal
indexed array? The typical test used is something like this:
if (array_keys($array) == range(0, count($array) - 1)) {
// indexed
} else {
// associative
}
In the example the poster provided, it would be evaluated as an indexed
array.
I actually don't believe it is a problem at all. json_encode() will
preserve the key => value relationship if the integer keys are
non-contiguous. Otherwise, if they are, it's an indexed array.
It seems to me, judging by the original message, that the problem lies
in how Firebug, or something at that side of things, is interpreting
the data.
The original post:
today I tried to use the new Zend_Log_Writer_Firebug and it works
fine, but there is something irritating. If you log something like this:
# $logger->log(array('data' => array(0 => 1)), Zend_Log::DEBUG);
Firebug will show:
# array(['data'] => 1)
array('data' => array(0 => 1)) encodes correctly into {"data":[1]}
However, the output Firebug _should_ show, in this situation, given
the above JSON is: # array('data' => array(1))