ZF-11167: Have Zend_Json::encode check for a toArray() method as well
Description
Currently Zend_Json checks for the presence of a toJson() method when an object is involved:
ublic static function encode($valueToEncode, $cycleCheck = false, $options = array())
{
if (is_object($valueToEncode) && method_exists($valueToEncode, 'toJson')) {
return $valueToEncode->toJson();
}
My suggestion would be to alternatively also check for the presence of a toArray() object since these exist more often then tojson() methods and can be encoded just as well.
Comments
Posted by Adam Lundrigan (adamlundrigan) on 2011-08-28T03:16:13.000+0000
Attached patch for implementation + unit tests. Will commit to SVN once sufficient feedback has been received and (any) necessary modifications made.
Posted by Pádraic Brady (padraic) on 2011-08-28T13:43:06.000+0000
I've reviewed the patch and confirm it operates as intended. Recommend committing to trunk (need to check with Matthew on adding to release branch as it adds to the API). Please ensure a ZF2 git pull request including matching changes is issued for ZF2 before resolving.
Posted by Adam Lundrigan (adamlundrigan) on 2011-08-28T15:31:13.000+0000
Committed to trunk r24419
Posted by Adam Lundrigan (adamlundrigan) on 2011-08-28T20:06:08.000+0000
Opened pull request on {{zendframework:zf2}} branch {{master}} https://github.com/zendframework/zf2/pull/362