search

Home  >  Q&A  >  body text

php - When using the is_int function, when the number to be determined exceeds 9 digits, false is returned. Why?

When using the is_int function, PHP returns false when the number to be determined exceeds 9 digits. Why?

大家讲道理大家讲道理2810 days ago1058

reply all(2)I'll reply

  • 滿天的星座

    滿天的星座2017-05-16 13:06:03

    . . . .
    Integer integer type has a range, and this range is different from the range of 32-bit (maximum value: 2^31 - 1) and 64-bit (maximum value: 2^63 - 1) related to the platform version. At this time, numbers out of the range will be interpreted as float type, so the is_int() function judgment will be false. The following is a 64-bit integer overflow:

    $large_number = 9223372036854775807;
    var_dump(is_int($large_number));                     // true
    
    $large_number = 9223372036854775808;
    var_dump(is_int($large_number));                    // false

    reply
    0
  • 世界只因有你

    世界只因有你2017-05-16 13:06:03

    According to php official website manual:

    The word length of integers is platform-dependent, although the usual maximum is about two billion (32-bit signed). The maximum value on 64-bit platforms is usually around 9E18, except for versions prior to PHP 7 on Windows, which were always 32-bit. PHP does not support unsigned integer. The word length of an Integer value can be represented by the constant PHP_INT_SIZE. Since PHP 4.4.0 and PHP 5.0.5, the maximum value can be represented by the constant PHP_INT_MAX, and the minimum value can be represented by the constant PHP_INT_MIN in PHP 7.0.0 and later versions. .

    So for a 32-bit integer, signed 2^31=2147483648 (about 2 billion), it is a 10-digit number, so for the situation you mentioned, it is true that more than 9 digits will return false.

    reply
    0
  • Cancelreply