views:

198

answers:

8

the following statement returns "do actions!what2" when run. What's going on here? it seems like both true and false are being returned!

if (md5($email) == $emailHash) {
    echo "do actions!";
} else {
    echo "what2";
}
+1  A: 

Is this the actual code that this problem is occurring in? Because how it is now, there is no way that could happen. If it's not your actual code, check to see if you have a semicolon after your conditional but before the first block.

ryeguy
+4  A: 

Double function call where both the true condition and false condition are displayed? You can generate a stacktrace by using the debug_print_backtrace function and see if it's called more than once.

TheGrandWazoo
+1  A: 

If the code is in a for or while loop (or is otherwise being called twice such as in a function), then it could be that the if is evaluating true the first time and false the second time. Otherwise, I don't see any reason why that would be happening.

waiwai933
+1  A: 

I guess the surrounding code is doing the wrong. Nothing wrong with this one. Also try putting in three equal signs === in your if condition rather than two.

Sarfraz
+1  A: 

no chance - you're calling the code twice!

Matt Joslin
A: 

I think we need more code than just your if condition. On my box i got an "what2" which is correct.

if (md5($email) === $emailHash) 
{
    echo "do actions!";
}
else 
{
    echo "what2";
}
streetparade
A: 

There is no way that this can happen. More often we think that there is bug in the language when we are sure that, we haven't done any thing wrong. But there is always some thing silly in the code. You must check the code again.

Chetan sharma
+1  A: 

I don't know what exactly is going on there, but I am used into doing something like this for the same problem:

$userHash = md5($email);
if ($userHash == $emailHash) {
  // etc...
}

Therefore doing one thing per statement at a time, making the debugging easier.

dimitris mistriotis