Bug #67439 [Com]: php 64-bit treats not so large integer literals as doubles

From: Date: Fri, 13 Jun 2014 17:41:43 +0000
Subject: Bug #67439 [Com]: php 64-bit treats not so large integer literals as doubles
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-186186@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=67439&edit=1 ID: 67439 Comment by: yuri dot kanivetsky at gmail dot com Reported by: yuri dot kanivetsky at gmail dot com Summary: php 64-bit treats not so large integer literals as doubles Status: Not a bug Type: Bug Package: *General Issues Operating System: windows 8 64-bit PHP Version: 5.5.13 Block user comment: N Private report: N New Comment: 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 Previous Comments: ------------------------------------------------------------------------ [2014-06-13 17:16:47] 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 15:04:33] 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 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=67439&edit=1

« previous php.bugs (#186186) next »