It really seems to be a "bug" in Firebug. PHP en-/decodes json strings correct.

{"data":[1]}     = array("data" => array(0 => 1))
{"data":[1,2,3]} = array("data" => array(0 => 1, 1 => 2, 2 => 3))

Firebug is showing {"data":[1]} as an single dimension array with key=>value. Its very inconsequent to decode {"data":[1]} to an single dimension array but decode {"data":[1,2,3]} to an two dimensional array.

Regards,
Jan Pieper


-- 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 am working on a solution but do not have a timeline yet.

Thanks for reporting your use-case. I have added a comment to the ticket.

Christoph



Jan Pieper wrote:
Hi guys,

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)

It is because the given array will be encoded to {'data':[1]} and []
is no associated array but I think the result is something
"completely" different.

# array('data' => array(0 => 1)) != array('data' => 1)

Is there a chance to get it fixed or is it a Firebug issue?

Regards,
Jan Pieper


--
Christoph Dorn
<http://www.ChristophDorn.com/>   http://www.ChristophDorn.com/



Reply via email to