Strange problem with an ^= operator

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Philarmon
Forum Newbie
Posts: 2
Joined: Sun Feb 18, 2007 1:44 pm

Strange problem with an ^= operator

Post by Philarmon »

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 !
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Bit manipulation functions such as this (xor) work a bit differently between different builds. This is due to the platform, but can also be due to version variances. Normally such a low value doesn't have such great effect.

You may need to alter the code so it comes to the expected result reliably.
Philarmon
Forum Newbie
Posts: 2
Joined: Sun Feb 18, 2007 1:44 pm

Post by Philarmon »

feyd wrote:You may need to alter the code so it comes to the expected result reliably.
Yes, that is exactly what i thought about - if i just would know how do i alter it :) The problem is that i even not understand what it dies :)

Thanks for your time. Any suggestions about how do i do that ?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

The first thing to do is probably learn how the operator works. Next understand what it's actually doing and finally build an equivalent.

It will involve combinations of the basic math functions.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Could this problem have anything to do with 32-bit vs. 64-bit architecture of the systems the install is on and how PHP handles floating point numerics on these types of architectures?
Post Reply