Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I have a 64-bit integer in PHP?

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.

like image 610
nonopolarity Avatar asked May 14 '09 15:05

nonopolarity


People also ask

How do you create a 64-bit integer?

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.

What is the integer limit for 64-bit?

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).

What is the limit of PHP integer value?

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.

Is PHP 32 or 64-bit?

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.


2 Answers

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 
like image 64
scotts Avatar answered Oct 06 '22 02:10

scotts


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.

like image 37
tmont Avatar answered Oct 06 '22 02:10

tmont