Re: json_decode() and integers larger than LONG_MAX (2^31 - 1)

From: Date: Thu, 20 May 2010 19:58:52 +0000
Subject: Re: json_decode() and integers larger than LONG_MAX (2^31 - 1)
References: 1  Groups: php.internals 
Request: Send a blank email to internals+get-48365@lists.php.net to get a copy of this message
hi Sara, The idea sounds sane, until we have big integer support :) Only one thing, I would suggest to use JSON_BIGINT_AS_STRING instead, more clear about its effect. Cheers, On Thu, May 20, 2010 at 9:50 PM, Sara Golemon <pollita@php.net> wrote: > I know this issue has been seen before, but I hope to do something about it. > > $json = '1234567890123456789'; > $x = json_decode($json); > /* $x is now a float *aproximately* >  * equal to the original value >  */ > > For database indexes, being off by one can be disasterous for application > flow, so I'd like to include the option to decode very large integers as > strings. > > To that end, I propose a change in json_decode()'s signature to add an > optional fourth argument, mirroring json_encode()'s second argument: > > mixed json_decode(string $json[, bool $assoc = false[, int $depth = 512[, > int $options]]]); > > Where $options is a bitmask of zero or more of the following: > > JSON_BIGINT_STRING - Store large integers as their original string value > > With the corresponding simple changes in json.c and JSON_parser.c > > If noone objects or offers comments, I'll implement this. > > -Sara > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Pierre @pierrejoye | http://blog.thepimp.net | http://www.libgd.org

« previous php.internals (#48365) next »