Why does this if statement, with an assignment and equality check, evaluate to false?

The expression is not parsed the way you think. It’s not

(test1=false) || (test1 == false)

in which case the result would have been true, but

test1 = (false || test1 == false)

The value of false || test1 == false expression is computed first, and it is false, because test1 is set to true going into the computation.

The reason it is parsed this way is that the precedence of the || is lower than that of the == operator, but higher than the precedence of the assignment operator =.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)