Strange problem with an ^= operator

Discussion in 'PHP' started by Philarmon, Feb 18, 2007.

  1. #1
    Hello !

    Hopefully someone can help me with this weird problem :)

    I got a script that works just fine on my local machine but is going mad on my web server. After a lot of tracing i figured out that this line returns two different values on my machine and on the web server:

    $a ^= (43814);

    The result on my local machine is -443704711 and on the web server it is -2147439834 .

    Now i am not a PHP guru at all and i even don't know what this line is supposed to do, its just pretty strange that the same thing works differnet on different servers :)

    Now, as far as i know there are two differences between my local server (its an xampp package) and my webserver:

    My server:
    Windows machine
    PHP 5.1.4 installed

    Web server:
    Linux
    PHP 5.2.0

    I hope someone knows about this problem and can suggest a workaround ?

    Oh, and at least - what is this line about ? :)

    Thank you !
     
    Philarmon, Feb 18, 2007 IP
  2. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #2
    as far as i do remember ^ is a bitwise OR operator used in C/C++ programming

    as far as php concern it does some kind bit shifting please check following link for more details and its definaly gonna affect the script on windows and UNIX platforms

    http://theopensourcery.com/phplogic.htm
     
    rays, Feb 19, 2007 IP
  3. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #3
    rays, Feb 19, 2007 IP
  4. wmtips

    wmtips Well-Known Member

    Messages:
    601
    Likes Received:
    70
    Best Answers:
    1
    Trophy Points:
    150
    #4
    The line
    $a ^= (43814);
    PHP:
    is a short equivalent for
    $a = $a ^ 43814;
    PHP:
    ^ is a XOR (eXclusive OR), and it must return the same results if you have equal $a values on your test server and web server. So try to output $a and make sure it is the same.
     
    wmtips, Feb 20, 2007 IP
  5. rays

    rays Active Member

    Messages:
    563
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #5
    wmtips can you please explain more about eXclusive OR AND etc
     
    rays, Feb 21, 2007 IP
  6. picouli

    picouli Peon

    Messages:
    760
    Likes Received:
    89
    Best Answers:
    0
    Trophy Points:
    0
    #6
    http://php.net/language.operators.bitwise

    Anyway, 99% on the times people ask about these operators on these forums it's because they are used in the Google PageRank script (and they behave strangely with different machines/PHP versions)
     
    picouli, Feb 21, 2007 IP