Zend Framework

"Cycles not supported in JSON encoding": buggy

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 0.1.5
  • Fix Version/s: 0.6.0
  • Component/s: Zend_Json
  • Labels:
    None

Description

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.

Activity

Hide
Bill Karwin added a comment -

Scheduling for release 0.7.0.

Show
Bill Karwin added a comment - Scheduling for release 0.7.0.
Hide
Matthew Weier O'Phinney added a comment -

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.

Show
Matthew Weier O'Phinney added a comment - 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.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: