8

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?

Shaiful Islam
  • 7,034
  • 12
  • 38
  • 58
  • possible duplicate of [php 64 bit with php\_int\_max = 2147483647](http://stackoverflow.com/questions/17837157/php-64-bit-with-php-int-max-2147483647) – xmojmr Jan 09 '15 at 17:34
  • possible duplicate of [how to have 64 bit integer on PHP?](http://stackoverflow.com/questions/864058/how-to-have-64-bit-integer-on-php) – xmojmr Jan 09 '15 at 17:38

2 Answers2

7

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.

Community
  • 1
  • 1
dynamic
  • 46,985
  • 55
  • 154
  • 231
  • 6
    This isn't true for PHP 7 anymore, it was for PHP 5.6 though with the [official builds](http://windows.php.net/download). – Seth Jan 26 '17 at 11:09
1

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

Snowbases
  • 2,316
  • 2
  • 20
  • 26