Unreliable php exclusive or operations

Source: Internet
Author: User
Tags php windows
However, it seems that there is a problem on the server, and it is always impossible to get it, but there is no problem with local debugging. the allow_url_fopen of php is on, and the file function test is successful, which is strange, you have time to proceed. Written yesterday


However, it seems that there is a problem on the server, and it is always impossible to get it, but there is no problem with local debugging. the allow_url_fopen of php is on, and the file function test is successful, which is strange, you have time to proceed.


After work today, I will study this again. during the careful analysis of the pr. php file, I found that the final focus problem lies in
$ A ^ = (zeroFill ($ c, 13 ).
<? Php
$ A =-3862272608;
$ B = 471468;
$ C = $ a ^ $ B;
Echo $ c;


Echo'
This is a 5.2 php Windows XP system. The value of $ c is 432886796 ';
Echo'
The value of $ c for the 4.4 php and CentOs system on the server is-2147012180 ';
?>


Based on the above code, you can test it by yourself. The results of linux and windows are different.
It makes me very depressed. echo get_1__var ('Precision '); the accuracy of this query is the same.


Then Baidu found the following excerpt from the cu post:


Said the landlord


For the same code, php in linux and windows is different or the result is different. why?
The code is
<?
$ A =-5547163286;
$ B = 173240;
$ A ^ = $ B;
Echo $;
?>
In linux, the result is-2147310408.
In windows, the result is-1252022830.


What's going on? Have you ever met?




Second floor
This should not be a system problem. it should be a machine problem.


Third floor
After following up, the message is sent out.
The value range of an integer in php is 2147483647 ~ -2147483647
Therefore, the above value $ a is theoretically overflow.
But the strange thing is that, after the value is assigned, echo $ a again, and the overflowed value is printed.
Why?
I cannot touch the North ......


Fourth floor
The length of the integer is related to the platform, although the maximum value is usually about 2 billion (32-bit signed ). PHP does not support unsigned integers.


Fifth Floor
To: HonestQiao
Moderator, Hello, the platform is related to the operating system, right?
How can I execute
$ A =-5547163286;
$ B = $;
The result of echo $ B; is-5547163286;
Since it overflows, $ B should not be the original value after the value is assigned.


6th Floor
Check whether this problem can be solved.


7th Floor
Http://cn.php.net/manual/zh/language.types.integer.php
Combination:
Http://cn.php.net/manual/zh/language.types.type-juggling.php
Take a look:
You can test separately:
$ A =-5547163286;
Printf ("% s \ n", gettype ($ ));
$ B = $;
Printf ("% s \ n", gettype ($ B ));
$ A =-5547163286;
Printf ("% s \ n", gettype ($ ));
$ B = 173240;
Printf ("% s \ n", gettype ($ B ));
$ A ^ = $ B;
Printf ("% s \ n", gettype ($ ));
Echo $;


Eighth Floor
According to the prompts in HonestQiao, the test results are as follows:
Test 1:
<?
$ A =-5547163286;
Printf ("% s \ n", gettype ($ ));
$ B = 173240;
Printf ("% s \ n", gettype ($ B ));
$ A ^ = $ B;
Printf ("% s \ n", gettype ($ ));
Echo $;
?>
Result: double integer-2147310408
Test 2:
<?
$ A =-5547163286;
Printf ("% s \ n", gettype ($ ));
$ B = (double) 173240;
Printf ("% s \ n", gettype ($ B ));
$ A ^ = $ B;
Printf ("% s \ n", gettype ($ ));
Echo $;
?>
Result: double integer-2147310408
Test 3:
<?
$ A =-5547163286;
Printf ("% s \ n", gettype ($ ));
$ B = (double) 173240;
Printf ("% s \ n", gettype ($ B ));
$ A = (double) ($ a ^ $ B );
Printf ("% s \ n", gettype ($ ));
Echo $;
?>
Result: double-2147310408


The calculation result is-2147310408, which is an incorrect value.
I now basically think that the large numbers of php in linux may be different or exceptions or errors may occur.
What do you think?




9th floor
I mean, it will convert the data type.
At the same time, when the range is exceeded, the behavior is unpredictable.
Then I ran back to a post.
So far. It can be determined that the reason is the server.
The value range of an integer in php is 2147483647 ~ -2147483647
In linux, php integer overflow results are unreliable.
That is to say, this pr query can only be used on windows servers .......

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.