My operating System is windows 7 and 64bit.
Now I run following code:
echo PHP_INT_SIZE;//prints 4
echo PHP_INT_MAX;//prints 2147483647
But I think it should be 8
and (2^63-1)//^ represents power
Can anyone explain me why this happen?
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.
Check php_uname string The php_uname returns the system/OS information, the parameter 'm' will ask for the machine type. In 64-bit, it will contain the string 'x86_64' so we can use this to test if it is 64-bit PHP.
Integer size are always compiler/interpreter/platform dependent (this applies for other languages too).
In the case of PHP on Windows it does not support 64-bit integers at all, even if both the hardware and PHP are 64-bit
On windows x86_64, PHP_INT_MAX is 2147483647. This is because in the underlying c-code, a long is 32 bit.
Linux on x86_64 uses a 64bit long so PHP_INT_MAX is going to be 9223372036854775807.
If you need a bigger precision you could use either GMP or BCMath extension.
Tip: never make assumptions on the max value a type will be able to handle unless you need exactly on which php version/platform the code will run.
Your OS is 64-bits. Your PHP version is x86.
How to determine the PHP version is using the constant
PHP_INT_SIZE will return 4 for x86 version
PHP_INT_SIZE will return 8 for x64 version
Related info:
Doubleword: a 4-byte (32 bit) data item
Quadword: an 8-byte (64 bit) data item
Hope that's clear :)
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