PHP built-in functions 32-bit and 64-bit platform compatibility issues _php Tutorial

Source: Internet
Author: User
www.Bkjia.com Tutorial The integer in PHP is the long type in the C language, is signed, and the maximum value is 2^31. On a 64-bit platform, long can reach 2^63.

In this case, some of the results of the PHP function output will be inconsistent on each platform.

Php-r "Echo ip2long (' 255.255.255.255 ');" under 64-bit platforms is: 4294967295, 32-bit platform is-1. There are, for example, filesize when the file is larger than 2G, the results are inconsistent on different platforms.

The solution to this problem is simple, sprintf ("%u", FileSize ($file)). Converts the result to a string. Why would the result be the same: the complement of the unsigned number 4294967295 and the signed number-1 are the same. Similarly, a function that returns an int with the last result that may be greater than 2^31 is handled in such a way.

Note that although the return is a string, PHP will automatically reload when arithmetic is performed. If the number greater than 2^31 is converted to int if it is greater than, it is converted to double.

http://www.bkjia.com/PHPjc/364353.html www.bkjia.com true http://www.bkjia.com/PHPjc/364353.html techarticle Fire Net (liehuo.net) tutorial The integer in PHP is the long type in the C language, is signed, and the maximum value is 2^31. On a 64-bit platform, long can reach 2^63. In this case, some ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.