gpt4 book ai didi

PHP 5.6.12 - 整数返回不正确

转载 作者:可可西里 更新时间:2023-11-01 00:59:15 25 4
gpt4 key购买 nike

以前我一直在 Linux 中使用 PHP 5.6.7 开发应用程序,但最近我切换到使用 WAMP 64 位的 Windows 环境并将 PHP 升级到 5.6.12 并遇到了一些问题。一个问题是在后端 PHP 中,我有一个整数数组。当我打印返回到前面将返回数组打印到控制台时,我得到了不同的格式。即:

$permission->fk_org_id = [24053826281537536,24051529749102626,111];
print json_encode($permission->fk_org_id);

将以下内容返回到控制台:

0:24053826281538000
1:24051529749103000
2:111

为什么会这样?

最佳答案

这些数字太大而不适合(32 位)整数。它们将被解释为 float ,参见 documentation :

If PHP encounters a number beyond the bounds of the integer type, it will be interpreted as a float instead. Also, an operation which results in a number beyond the bounds of the integer type will return a float instead.

A float具有大约 14 位有效数字的精度,所以这就是您看到零的原因。

不幸的是,Windows 上的 PHP 不支持 64 位整数,根据 this answer :

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 64bit long so PHP_INT_MAX is going to be 9223372036854775807.

关于PHP 5.6.12 - 整数返回不正确,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32095876/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com