PHP_INT_SIZE返回4,但是我的操作系统是64位 [英] PHP_INT_SIZE returns 4 But my Operating System Is 64 bit

查看:290
本文介绍了PHP_INT_SIZE返回4,但是我的操作系统是64位的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的操作系统是Windows 7和64位.
现在,我运行以下代码:

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

但是我认为应该是8(2^63-1)//^ represents power

谁能解释我为什么会这样?

Can anyone explain me why this happen?

推荐答案

整数大小始终取决于编译器/解释器/平台(这也适用于其他语言).
对于Windows上的PHP,即使硬件和PHP均为64位,它也根本不支持64位整数

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

在Windows x86_64上,PHP_INT_MAX为2147483647.这是因为在基础c代码中,long是32位.

On windows x86_64, PHP_INT_MAX is 2147483647. This is because in the underlying c-code, a long is 32 bit.

x86_64上的Linux使用64位长,因此PHP_INT_MAX将为9223372036854775807.

Linux on x86_64 uses a 64bit long so PHP_INT_MAX is going to be 9223372036854775807.

如果您需要更高的精度,可以使用 GMP BCMath 扩展名.

If you need a bigger precision you could use either GMP or BCMath extension.

提示:除非您确切需要代码将在哪个php版本/平台上运行,否则永远不要假设类型可以处理的最大值.

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.

这篇关于PHP_INT_SIZE返回4,但是我的操作系统是64位的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆