Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:42235 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 92766 invoked from network); 13 Dec 2008 18:09:57 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 13 Dec 2008 18:09:57 -0000 Authentication-Results: pb1.pair.com header.from=chris_se@gmx.net; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=chris_se@gmx.net; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmx.net designates 213.165.64.20 as permitted sender) X-PHP-List-Original-Sender: chris_se@gmx.net X-Host-Fingerprint: 213.165.64.20 mail.gmx.net Linux 2.5 (sometimes 2.4) (4) Received: from [213.165.64.20] ([213.165.64.20:46184] helo=mail.gmx.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A8/86-47862-37AF3494 for ; Sat, 13 Dec 2008 13:09:56 -0500 Received: (qmail invoked by alias); 13 Dec 2008 18:09:52 -0000 Received: from p54A160BB.dip.t-dialin.net (EHLO chris-se.dyndns.org) [84.161.96.187] by mail.gmx.net (mp027) with SMTP; 13 Dec 2008 19:09:52 +0100 X-Authenticated: #186999 X-Provags-ID: V01U2FsdGVkX1+uFPEtD3muqKPtnCi1GN1rA1OXKjq5OsCnL/E4xi X5/9R17gm1qEEc Received: from [192.168.0.175] (HSI-KBW-082-212-059-033.hsi.kabelbw.de [82.212.59.33]) by chris-se.dyndns.org (Postfix) with ESMTP id D4C8A67DD; Sat, 13 Dec 2008 18:58:17 +0100 (CET) Message-ID: <4943FA42.3000806@gmx.net> Date: Sat, 13 Dec 2008 19:09:06 +0100 User-Agent: Thunderbird 2.0.0.17 (X11/20080914) MIME-Version: 1.0 To: Ilia Alshanetsky CC: Scott MacVicar , PHP Developers Mailing List References: <2D85B33E-889B-4214-9BB8-A12EFFFC641E@macvicar.net> In-Reply-To: X-Enigmail-Version: 0.95.7 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Y-GMX-Trusted: 0 X-FuHaFi: 0.5600000000000001 Subject: Re: [PHP-DEV] Re: Removing basic types from our JSON parser From: chris_se@gmx.net (Christian Seiler) Hi, >> Basic types were added to our JSON decoder to PHP 5.2.1, this allows >> one to use json_encode / json_decode on any of our scalar types. Omar >> correctly identified #38680 as not a bug but it appears that Ilia >> added support for this anyway violating the RFC [1]. Maybe there was a >> reason for this but I'm not sure why? > > PHP is typeless language, IMO its conductive to this design to allow > encoding of basic types via json_encode, it reduces the code when > communicating to/form JavaScript to avoid type detection. While it does > violate the RFC IMO the convenience of the feature is definitely worth it. I agree that it's convenient for exporting variables to Javascript. On the other hand, one should always be lenient when accepting input but strict when generating output. Having json_encode encode non-arrays and non-objects by default will probably allow some people to shoot themselves in the foot when interfacing with other JSON applications. Thus I'd propose the following: json_encode already posesses an $options parameter that allows one to specify certain options for encoding as a bitmask. My proposal would be to add another option PHP_JSON_ENCODE_BASIC to allow the encoding basic types. When set, json_encode("hi") and json_encode(42) will work without any problem. When not set, I propose the following behaviour when passing a string or integer etc.: * PHP 5.3: An E_DEPRECATED-Warning which mentions the new option but still return the result. * PHP 6: Return false or whatever it currently returns when encoding wasn't possible and throw an E_WARNING. Regards, Christian