Re: json_encode()

From: Date: Mon, 15 Dec 2008 18:09:47 +0000
Subject: Re: json_encode()
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-42267@lists.php.net to get a copy of this message
On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf <rasmus@lerdorf.com> wrote: > 1. Document the fact that if you want to strictly conform to the JSON > spec and be sure your json_encode output will work in various JSON > parsers, you have to pass it a PHP array or object. Instead of json_encode(34) the suggestion would be json_encode(array(34)) ? Seems kind of like a lame thing to require. IMHO the language should "do the right thing" as far as the consumer (javascript/JSON parser) is concerned. However, Douglas is infinitely more educated than I am here. This is just my $0.02 as a PHP user. > 2. Remove support for basic types entirely and throw an error if you > pass json_encode() something that is not an array or an object. > > 3. Wrap basic types in an array [] by default and perhaps add an option > to json_encode() to skip the wrapper. This sounds like what I had been talking about previously. > He would prefer option 1. I'd be tempted to say #3. However that's probably a code change everyone must make, I would expect that to be in a major release like 6.0.

« previous php.internals (#42267) next »