Re: json_encode()
| From: | Richard Quadling | Date: | Tue, 16 Dec 2008 11:48:33 +0000 |
| Subject: | Re: json_encode() | ||
| References: | 1 2 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-42284@lists.php.net to get a copy of this message | ||
2008/12/15 mike <mike503@gmail.com>:
> 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.
I was one of those that read the PHP dox and not the RFC/standard
(http://bugs.php.net/bug.php?id=38680).
I would say that having PHP "correct" my mistake is wrong.
If I say...
json_encode(34);
I am saying that I expect the result to be ...
var i_SomeInt = 34;
And from there I would expect to be able to say ...
var i_SomeOtherInt = i_SomeInt + 10;
This is not going to work if PHP "corrects" my mistake.
I'd be perfectly happy for the standard to be enforced and an E_STRICT
warning to be raised.
If I want to shoot myself then I have to at least take the safety off
first - turning off E_STRICT that is.
Essentially, I don't like computers guessing my intent. If I don't
state it clearly enough then it may be that I don't know what I'm
doing.
GIMGO (Garbage In, Maybe Garbage Out) isn't a good way to go.
Richard.
--
-----
Richard Quadling
Zend Certified Engineer : http://zend.com/zce.php?c=ZEND002498&r=213474731
"Standing on the shoulders of some very clever giants!"