ZF-8618: Zend_Json_Decoder returns incompatible return types compared to ext/json

Description

Zend_Json_Decoder (the native alternative to ext/json) returns types which are incompatible with ext/json, thus for the same JSON input ext/json may emit a stdClass object whereas Zend_Json_Decoder emits an Array instead. Given the access differences this incompatibility may break applications moving from an ext/json system to one (e.g. CentOS) where ext/json is not available and Zend_Json_Decoder is utilised instead.

Reproduce code:

'));
var_dump(Zend_Json_Decoder::decode('{"zero": 2}'));

Expected:

object(stdClass)#1 (1) { ["zero"]=> int(2) } object(stdClass)#1 (1) { ["zero"]=> int(2) }

Actual:

object(stdClass)#1 (1) { ["zero"]=> int(2) } array(1) { ["zero"]=> int(2) }

Comments

you must pass the second parameter of the function.

var_dump(Zend_Json_Decoder::decode('{"zero": 2}',TYPE_OBJECT));

ext/json doesn't require the extra parameter - so it is an incompatible behaviour ;).

json_decode defaults to returning an object of type stdClass, but Zend_Json::decode defaults to returning an array whether it uses json_decode or its own internal decoder. I can see how this is confusing and inconsistent. However, if we change the default behavior, wouldn't that break backwards compatibility? This behavior has been in place since they added support for ext/json. Thoughts?

Perhaps in ZF2 the default could change? I can't see a way to change the default behavior without breaking backwards compatibility.