ZF-11854: Zend_Json::prettyPrint causes warning when empty array given

Description

When empty array is given to Zend_Json::prettyPrint, it causes two warnings:


Zend_Json::prettyPrint(array());

Output: {quote} Warning: preg_split() expects parameter 2 to be string, array given in /usr/share/php5/Zend-1.11.11/Json.php on line 373 Warning: Invalid argument supplied for foreach() in /usr/share/php5/Zend-1.11.11/Json.php on line 403 {quote}

The encode() works properly:


echo Zend_Json::encode(array());

Output: {quote} [] {quote}

Comments

This is not a valid usage of {{Zend_Json::prettyPrint}}. That function accepts only JSON-encoded strings. To work correctly, your first code sample would have to look like this:


Zend_Json::prettyPrint(Zend_Json::encode(array()));

Method signature for {{Zend_Json::prettyPrint}}:


/**
 * Pretty-print JSON string
 *
 * Use 'format' option to select output format - currently html and txt supported, txt is default
 * Use 'indent' option to override the indentation string set in the format - by default for the 'txt' format it's a tab
 *
 * @param string $json Original JSON string
 * @param array $options Encoding options
 * @return string
 */
public static function prettyPrint($json, $options = array())