ZF-12410: Zend_Json Json View Helper in json() function passes a boolean as second argument to array_key_exists


When using Zend_Json View Helper with version ZF 1.12.0 get this warning:

array_key_exists() [function.array-key-exists]: The second argument should be either an array or an object in Zend/View/Helper/Json.php on line 67

This was not an issue with my previous version ZF 1.10.8.

Here it is why, I guess: see in Zend/View/Helper/Json.php :

The part where $encodeData is set, it uses a variable $keepLayouts as second argument for array_key_exists(). But such $keepLayouts is not an array nor an object anymore! In fact it was just assigned to a boolean value two lines above!

This bug was not here in version 1.10.8 because the $encodeData stuff has been added in a later version.

A possible solution may be to use the variable $options to test with array_key_exists(), but please check it out!

public function json($data, $keepLayouts = false, $encodeData = true)
        $options = array();
        if (is_array($keepLayouts))
            $options     = $keepLayouts;
            $keepLayouts = (array_key_exists('keepLayouts', $keepLayouts))
                            ? $keepLayouts['keepLayouts']
                            : false;
            $encodeData  = (array_key_exists('encodeData', $keepLayouts))
                            ? $keepLayouts['encodeData']
                            : $encodeData;

        if ($encodeData) {
            $data = Zend_Json::encode($data, null, $options);
        if (!$keepLayouts) {
            // require_once 'Zend/Layout.php';
            $layout = Zend_Layout::getMvcInstance();
            if ($layout instanceof Zend_Layout) {

        $response = Zend_Controller_Front::getInstance()->getResponse();
        $response->setHeader('Content-Type', 'application/json', true);
        return $data;


No comments to display