Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42296 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 77065 invoked from network); 16 Dec 2008 16:37:37 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 16 Dec 2008 16:37:37 -0000 Authentication-Results: pb1.pair.com smtp.mail=ilia@prohost.org; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=ilia@prohost.org; sender-id=unknown Received-SPF: error (pb1.pair.com: domain prohost.org from 209.85.132.250 cause and error) X-PHP-List-Original-Sender: ilia@prohost.org X-Host-Fingerprint: 209.85.132.250 an-out-0708.google.com Received: from [209.85.132.250] ([209.85.132.250:35079] helo=an-out-0708.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id AE/31-05368-059D7494 for ; Tue, 16 Dec 2008 11:37:37 -0500 Received: by an-out-0708.google.com with SMTP id b2so1353978ana.38 for ; Tue, 16 Dec 2008 08:37:34 -0800 (PST) Received: by 10.64.195.20 with SMTP id s20mr7519881qbf.72.1229445454153; Tue, 16 Dec 2008 08:37:34 -0800 (PST) Received: from ?192.168.1.111? (TOROON63-1176059019.sdsl.bell.ca [70.25.60.139]) by mx.google.com with ESMTPS id k7sm2100528qba.26.2008.12.16.08.37.32 (version=TLSv1/SSLv3 cipher=RC4-MD5); Tue, 16 Dec 2008 08:37:32 -0800 (PST) Cc: RQuadling@GoogleMail.com, PHP Developers Mailing List Message-ID: To: Scott MacVicar In-Reply-To: <494797BE.3060505@macvicar.net> Content-Type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit Mime-Version: 1.0 (Apple Message framework v930.3) Date: Tue, 16 Dec 2008 11:37:31 -0500 References: <494698D3.2030801@lerdorf.com> <10845a340812160348k18bffb0et1e75cf345b5e42cc@mail.gmail.com> <494797BE.3060505@macvicar.net> X-Mailer: Apple Mail (2.930.3) Subject: Re: [PHP-DEV] json_encode() From: ilia@prohost.org (Ilia Alshanetsky) The proposed solution (basic types flag) is probably the lesser evil, but I still feel were are taking things to far and current operation is correct. On 16-Dec-08, at 6:57 AM, Scott MacVicar wrote: > Richard Quadling wrote: >> 2008/12/15 mike : >>> On Mon, Dec 15, 2008 at 9:50 AM, Rasmus Lerdorf >>> 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. >> > > json_encode is NOT javascript encode, you're already shooting yourself > by miusing the function. The problem I'm talking about here is when > native browser functions are used to decode the JSON. > > var json_resonse = ; > var myfoo = JSON.parse(json_resonse); > > The result here is an exception thrown by the browser, if you try and > use JSON to speak to perl, python or ruby you get a similar error. The > same applies for the various frameworks out there too. > > For now I'll be leaving it as is and adding a JSON_STRICT_ENCODE > parameter to the options flag. So you can use > > json_encode($var, JSON_STRICT_ENCODE); > > Scott > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > Ilia Alshanetsky