I'm trying to decode a JSON encoded string. This string contains a big
value (of type long).
The result in PHP is always 2147483647 (PHP s max integer value), see
the code below.
How to make PHP aware of the fact that we deal with a long value?
<?php
$input = '{ "abc" : 121212121212 }';
$val = json_decode($input, true);
echo '<pre>';
echo var_dump($val);
echo '</pre>';
?>
array(1) {
["abc"]=>
int(2147483647)
}
Rob
static void json_create_zval(zval **z, smart_str *buf, int type)
{
ALLOC_INIT_ZVAL(*z);
if (type == IS_LONG)
{
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else if (type == IS_DOUBLE)
{
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else if (type == IS_STRING)
{
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else if (type == IS_BOOL)
{
ZVAL_STRINGL(*z, buf->c, buf->len, 1);
}
else /* type == IS_NULL) || type unknown */
{
ZVAL_NULL(*z);
}
}
On Jul 28, 1:31 pm, "rjjuurl...@gmail.com" <rjjuurl...@gmail.com>
wrote:
> I'm trying to decode a JSON encoded string. This string contains a big
> value (of type long).
> The result in PHP is always 2147483647 (PHP s max integer value), see
> the code below.
>
> How to make PHP aware of the fact that we deal with a long value?
Try this patch:
http://treehou.se/~omar/php-json-ext-1.2.1-32bit_int.patch
This bug exists as I don't have any 32bit machines in active use. ;)
I'll be sure to test this on future releases.
Thanks.
> Rob
Regards,
Omar