ZF-461: "Cycles not supported in JSON encoding": buggy

Issue Type: Bug Created: 2006-10-26T12:32:23.000+0000 Last Updated: 2007-07-05T14:43:24.000+0000 Status: Resolved Fix version(s): - 0.6.0 (16/Dec/06)

Reporter: J.L. (ogregras) Assignee: Matthew Weier O'Phinney (matthew) Tags: - Zend_Json

Related issues: Attachments:


Zend_Json_Encoder doesn't allow an object to be repeated, even if this object is in two different locations.

Let's say what I want to encode contains : (1) a list of all my items (2) the currently selected item


class Item{} $item1 = new Item() ; $item2 = new Item() ; $everything = array() ; $everything['allItems'] = array($item1, $item2) ; $everything['currentItem'] = $item1 ;

$encoded = Zend_Json_Encoder::encode($everything);


The second time $item1 passes in _encodeObject(), it is seen as "visited" and Zend_Json_Encoder throws an exception.


Posted by Bill Karwin (bkarwin) on 2006-11-28T17:55:45.000+0000

Scheduling for release 0.7.0.

Posted by Matthew Weier O'Phinney (matthew) on 2006-12-08T14:08:13.000+0000

Detecting object recursion is next-to-impossible, due to the fact that an object has no idea what container it is in.

As a result, I introduced a second, optional parameter to Zend_Json::encode()/Zend_Json_Encoder::encode(), $cycleCheck. If true, it attempts to detect recursion as it has been doing, simply checking to see if an object has been serialized before in the current encoding session. Otherwise, the check is skipped. By default, the setting is off.

Have you found an issue?

See the Overview section for more details.


© 2006-2021 by Zend by Perforce. Made with by awesome contributors.

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