php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #81553 json_encode PHP_INT_MAX
Submitted: 2021-10-25 12:10 UTC Modified: 2021-10-25 12:52 UTC
From: khaledalam dot net at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Unknown/Other Function
PHP Version: 8.0.12 OS:
Private report: No CVE-ID: None
 [2021-10-25 12:10 UTC] khaledalam dot net at gmail dot com
Description:
------------
Getting different output values when use json_encode with big float  e.g. PHP_INT_MAX * PHP_INT_MAX

when use different php versions

https://3v4l.org/rBiTL

Test script:
---------------
<?php

$a = PHP_INT_MAX * PHP_INT_MAX;

$bb = json_encode($a, true);
$b = json_decode($bb);

var_dump($a);
var_dump($b);

Expected result:
----------------
same value regardless php version

float(8.507059173023462E+37)
or
float(8.5070591730235E+37)

Actual result:
--------------
Output for 8.0.0 - 8.0.12, 8.1rc1 - rc3
float(8.507059173023462E+37)
float(8.507059173023462E+37)

Output for 7.3.0 - 7.3.31, 7.4.0 - 7.4.25
float(8.5070591730235E+37)
float(8.5070591730235E+37)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-10-25 12:52 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2021-10-25 12:52 UTC] cmb@php.net
This has nothing to do with json_(en|de)code[1], but rather with
var_dump() which uses serialize_precision instead of precision as
of PHP 8.0.0[1].

[1] <https://www.php.net/manual/en/migration80.incompatible.php#migration80.incompatible.standard>
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 03:01:27 2024 UTC