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

Issue Type: Bug Created: 2012-09-07T19:07:25.000+0000 Last Updated: 2012-09-09T07:50:11.000+0000 Status: Closed Fix version(s): Reporter: Timido (timido) Assignee: Frank Br├╝ckner (frosch) Tags: - Zend_Json

  • json

Related issues: - ZF-12397



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!

<pre class="highlight"> 
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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.