How can I have a 64-bit integer in PHP?
It seems like it is not by a config file, but rather it might be a compile-time option, and it depends on the platform.
You can declare 8-, 16-, 32-, or 64-bit integer variables by using the __intN type specifier, where N is 8, 16, 32, or 64. The types __int8 , __int16 , and __int32 are synonyms for the ANSI types that have the same size, and are useful for writing portable code that behaves identically across multiple platforms.
A 64-bit signed integer. It has a minimum value of -9,223,372,036,854,775,808 and a maximum value of 9,223,372,036,854,775,807 (inclusive).
PHP Integers An integer data type is a non-decimal number between -2147483648 and 2147483647 in 32 bit systems, and between -9223372036854775808 and 9223372036854775807 in 64 bit systems. A value greater (or lower) than this, will be stored as float, because it exceeds the limit of an integer.
5) HOW TO CHECK FOR 32 OR 64 BITS PHP To check if you are running on 64-bit, just look under “Architecture” in phpinfo() – X86 is 32-bit, and X64 is 64-bit. Otherwise, if you want to test it out programmatically, you can check the PHP_INT_SIZE constant. It should be 4 for 32-bit, and 8 for 64-bit.
Native 64-bit integers require 64-bit hardware AND the 64-bit version of PHP.
On 32-bit hardware:
$ php -r 'echo PHP_INT_MAX;' 2147483647
On 64-bit hardware:
$ php -r 'echo PHP_INT_MAX;' 9223372036854775807
UPDATE: It does now (tested on AMD quad core, Windows 8.1).
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 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 64-bit long, so PHP_INT_MAX is going to be 9223372036854775807.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With