Re: JSON inclusion in core

From: Date: Mon, 23 Jan 2006 18:22:56 +0000
Subject: Re: JSON inclusion in core
References: 1 2 3 4 5  Groups: php.internals 
Request: Send a blank email to internals+get-21656@lists.php.net to get a copy of this message
Mike Naberezny wrote:
Bart de Boer wrote:
Maybe introduce an optional second argument "decodetype" to json_decode() where you could pass on a constant like JSON_ARRAY or JSON_OBJECT? For example: $assoc_array = json_decode($json_string, JSON_ARRAY);
$object      = json_decode($json_string, JSON_OBJECT);
I'm not saying this is a bad idea but is it really necessary? It seems to just add extra complexity. If json_decode() returns an associative array then you can cast easily enough: $obj = (object)json_decode($jsonSerialized); Mike
That's not entirely true since the properties of the resulting object would then still be made out of associative arrays. (in stead of objects) I'm not saying it's necessary to have it return objects. I'm leaning towards associative arrays myself too. On the other hand, objects seem to be more consistent with the behaviour in Javascript. The specs seems to allow both. Hence my suggestion. Bart

« previous php.internals (#21656) next »