Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:85797 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 17690 invoked from network); 14 Apr 2015 06:33:48 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 14 Apr 2015 06:33:48 -0000 Authentication-Results: pb1.pair.com smtp.mail=indeyets@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=indeyets@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.170 as permitted sender) X-PHP-List-Original-Sender: indeyets@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:35171] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D4/41-08334-BC4BC255 for ; Tue, 14 Apr 2015 02:33:48 -0400 Received: by iejt8 with SMTP id t8so7443809iej.2 for ; Mon, 13 Apr 2015 23:33:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=content-type:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=u5TDCbksprXH2l5fYOYc2PWFKUk4JzVBhT+nLZnf6mw=; b=SFerJnifbg+Cz8AKYpTGdXTm4sXtchcKSWBH8iqFnLPEVrMv+jiCsoHuIfyhHsrV5T 74SWBWTrLo+HHmepWoMNtqO4fTnocfeBZz/sbHEM+7TKwqaamicUidWfijool1Cmu+E+ GpHjegP3ilaufxw/fapM1Rgk+cj0XTD6HyzoqnXQcrKn1jbR7ZxUS/JjUf3cWWlx11wm 2fdx3e0I8ZfpMlNRBzvrWIGhTUjTW6ylEnYblpLzmhdsOP2KKuIxwT3ty52U8cXjiYJ3 HkcBbg43KFVXXTFvpq5jWrI8J62ySWTO3G+xG4J5E+lZfgKM/Q4/vVl13l30Z6jun1qB HVfA== X-Received: by 10.50.79.202 with SMTP id l10mr22053686igx.7.1428993224185; Mon, 13 Apr 2015 23:33:44 -0700 (PDT) Received: from [10.0.1.8] ([91.219.26.208]) by mx.google.com with ESMTPSA id 130sm23324ioz.10.2015.04.13.23.33.41 (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 13 Apr 2015 23:33:42 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 8.2 \(2098\)) In-Reply-To: Date: Tue, 14 Apr 2015 09:33:38 +0300 Cc: PHP internals list Content-Transfer-Encoding: quoted-printable Message-ID: <4D090060-127D-4BA8-8C98-6E315EF077C0@gmail.com> References: To: Jakub Zelenka X-Mailer: Apple Mail (2.2098) Subject: Re: [PHP-DEV] JSON float number as string From: indeyets@gmail.com (Alexey Zakhlestin) > On 14 Apr 2015, at 07:31, Alexey Zakhlestin = wrote: >=20 > Feels a bit hackish > I think it is possible to introduce an overall better solution >=20 > We can expose result of json-tokenizing as a tree of objects: >=20 > JSON\Object > JSON\Array > JSON\String > JSON\Number > JSON\False > JSON\True > JSON\Null >=20 > then, it would be possible to introduce any number of experimental = userland implementations like the one proposed here I decided to elaborate toString(); } } class String extends Literal { } class Number extends Literal { public function toInt(); public function toFloat(); } class False extends Literal { } class True extends Literal { } class Null extends Literal { } So, in case of Number, there would be a way to get the value the way it = was stored in document using toString(), use toInt() or toFloat() to get = a value with possible precision loss or use toNative(), which would be = =E2=80=9Csmart=E2=80=9D and return int or float using the same logic, = which json_decode() uses now. It would work the other way round too. Object::toJson() would return = json-representation of the tree.