php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #67439 php 64-bit treats not so large integer literals as doubles
Submitted: 2014-06-13 15:04 UTC Modified: 2014-06-13 17:44 UTC
From: yuri dot kanivetsky at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.5.13 OS: windows 8 64-bit
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: yuri dot kanivetsky at gmail dot com
New email:
PHP Version: OS:

 

 [2014-06-13 15:04 UTC] yuri dot kanivetsky at gmail dot com
Description:
------------
I'm using php-5.5.13. This bug makes json_encode generate wrong output, when values are high enough (they are represented in scientific notation, like 1.00001279446E+14). Also, it makes json_decode generate values of wrong data type, when large integers are encountered. The output on debian squeeze with php-5.4.10 is as expected.

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

$v = 2147483647;
echo $v . " - " . gettype($v) . "\n";
$v = 2147483648;
echo $v . " - " . gettype($v) . "\n";

Expected result:
----------------
2147483647 - integer
2147483648 - integer

Actual result:
--------------
2147483647 - integer
2147483648 - double

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-06-13 17:16 UTC] aharvey@php.net
-Status: Open +Status: Not a bug
 [2014-06-13 17:16 UTC] aharvey@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

PHP uses the long type for integers, and on Windows that's always a 32 bit integer, even on a 64 bit build.
 [2014-06-13 17:41 UTC] yuri dot kanivetsky at gmail dot com
Is this documented? The best info I could find: 


Note that PHP on Windows does not support 64-bit integers at all, even if both the hardware and PHP are 64-bit. See this link (http://permalink.gmane.org/gmane.comp.php.devel/55886) for details:

> On windows x86_64, PHP_INT_MAX is 2147483647. This is because in the underlying c-code, a long is 32 bit.

> However, linux on x86_64 uses a 64bit long so PHP_INT_MAX is going to be 9223372036854775807.

http://stackoverflow.com/a/3233881/52499


Current PHP zval datatype implementation uses long datatype to handle signed integer and int datatype to handle string length. The most 64 bit capable platforms PHP is used on are LP64 (Linux/most Unix-like), LLP64 (Windows), ILP64 (SPARC64). The data model used for the relevant datatypes on those platforms looks as follows

           string size  signed integer
Platform       int           long
LP64         32 bit         64 bit
LLP64        32 bit         32 bit
ILP64        64 bit         64 bit

Regarding PHP that means today, even on 64 bit platforms the following features lack on consistency

* handling of strings >= 2^31
* handling of 64 bit integers
* large file support
* handling of numeric 64 bit hash keys

https://wiki.php.net/rfc/size_t_and_int64
 [2014-06-13 17:44 UTC] aharvey@php.net
It's probably not as well documented as it should be. I'll tinker with the integers page a bit to make it clearer.
 
PHP Copyright © 2001-2026 The PHP Group
All rights reserved.
Last updated: Tue Oct 06 07:00:02 2026 UTC