强制转换为32位整数可能导致截断PHP Propel? [英] Cast to a 32 bit integer may result in truncation PHP Propel?

查看:177
本文介绍了强制转换为32位整数可能导致截断PHP Propel?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看Propel的源代码(PHP ORM库),我在propel / propel1 / runtime / lib / query / Criteria.php文件中找到了这个方法:

Looking at the source code of Propel (the PHP ORM library), I have found this method inside the propel/propel1/runtime/lib/query/Criteria.php file:

  /**
     * Set offset.
     *
     * @param int $offset An int with the value for offset.  (Note this values is
     *                    cast to a 32bit integer and may result in truncation)
     *
     * @return Criteria Modified Criteria object (for fluent API)
     */
    public function setOffset($offset)
    {
        $this->offset = (int) $offset;

        return $this;
    }

为什么在doc评论中他们说输入int的值可能会导致截断???不是int保持在例如在64位环境中 4000000000 ?实际上,它是,为什么这个注意?

Why in the doc comments they say that the value casted to int may result in truncation??? Isn't the int kept to e.g. 4000000000 in 64 bit environment? Actually, it is, so why this "Note"?

感谢您的关注!

推荐答案

整数的最大和最小大小取决于PHP的构建:32或64位(操作系统和处理器也必须遵循)

The maximum and minimum size of integer depends of the build of PHP : 32 or 64 Bits (operating system and processor must also follow)

对于 PHP 32位,范围介于] -2147483648 之间, 2147483647 [

对于 PHP 64位范围介于] -9223372036854775808 9223372036854775807 [

For PHP 32-Bits the range is between ]-2147483648, 2147483647[
For PHP 64-Bits the range is between ]-9223372036854775808, 9223372036854775807[

我的测试( PHP 32位,WINDOWS 7 64位,Intel CORE i3 64位):

My Test (PHP 32-Bits, WINDOWS 7 64-Bits, Intel CORE i3 64-Bits) :

<?php
$i = (int)2147483647;
var_dump($i);

将输出:

Will ouput :

int(2147483647)

第二次测试(仅增加1)最后一个值)

2nd test (just increment by 1 the last value)

<?php
    $i = (int)2147483647;
    var_dump($i);

将输出:

Will ouput :

int(-2147483648)

最后:确定一下您环境中整数的最大值,只需打印此

Finally : to be sure about the max value of integer in your environment, just print this

var_dump(PHP_INT_MAX);

这篇关于强制转换为32位整数可能导致截断PHP Propel?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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