ZF-4053: Silence cycle exception in Zend_Json_Encoder


I need a way to silence the exception thrown when cycle detection is switched on and one is detected in Zend_Json_Encoder.

This relates to issue ZF-4040.

The aim is to still generate a valid JSON string even if cycles are detected. In place of the repeated object we could insert

"* RECURSION ([Class Name]) *"

into the JSON string.

To accomplish this we could use:

protected function __construct($cycleCheck = false, $silenceCycleCheck = false)

or convert $_cycleCheck to an integer and introduce a Zend_Json_Encoder::SILENT_CYCLE_CHECK constant to avoid a new constructor/method argument.

Zend_Json_Encoder::encode($value, Zend_Json_Encoder::SILENT_CYCLE_CHECK);


Based on IRC discussion with Matthew we have decided to add an $options argument that accepts an associative array.

The option to silence the exception will be called "silenceCyclicalExceptions".

Updating for the 1.6.0 release.