Bug #79958 [NEW]: json_encode does not support JSON_BIGINT_AS_STRING
From: jmuraca at gmail dot com
Operating system: windows (all?)
PHP version: Irrelevant
Package: *General Issues
Bug Type: Bug
Bug description:json_encode does not support JSON_BIGINT_AS_STRING
Description:
------------
json_encode should be able to accept the parameter JSON_BIGINT_AS_STRING
to display large numbers as string and/or numeric rather than scientific
notation
my use case is a long number like that is used for some account
management identifiers (my included example is fake) and I want to json
output the whole number - not a scientific number
Test script:
---------------
// correct, displays scientific notation
$data = array("val" => 1008901020901566350119);
var_dump(json_encode($data));
// correct, displays val as string
$data = array("val" => "1008901020901566350119");
var_dump(json_encode($data));
// correct, displays val as numeric
$data = array("val" => "1008901020901566350119");
var_dump(json_encode($data, JSON_NUMERIC_CHECK));
// ERROR, displays val as scientific
// ideally with JSON_BIGINT_AS_STRING val display as numeric and full
number
$data = array("val" => "1008901020901566350119");
var_dump(json_encode($data, JSON_NUMERIC_CHECK|JSON_BIGINT_AS_STRING));
// ERROR, displays val as scientific
// ideally with JSON_BIGINT_AS_STRING val display as numeric and full
number
$data = array("val" => 1008901020901566350119);
var_dump(json_encode($data, JSON_BIGINT_AS_STRING));
Expected result:
----------------
$data = array("val" => "1008901020901566350119");
var_dump(json_encode($data, JSON_NUMERIC_CHECK|JSON_BIGINT_AS_STRING));
// actual: 1.0089010209015663e+21
// expected: 1008901020901566350119
$data = array("val" => 1008901020901566350119);
var_dump(json_encode($data, JSON_BIGINT_AS_STRING));
// actual: 1.0089010209015663e+21
// expected: 1008901020901566350119
--
Edit bug report at https://bugs.php.net/bug.php?id=79958&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=79958&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=79958&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=79958&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=79958&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=79958&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=79958&r=support
Expected behavior: https://bugs.php.net/fix.php?id=79958&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=79958&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=79958&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=79958&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=79958&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=79958&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=79958&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=79958&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=79958&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=79958&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=79958&r=mysqlcfg
Thread (8 messages)
- jmuraca at gmail dot com