Entry tags:
(no subject)
This is why PHP fails to make me happy. —Well, that's not quite accurate: Say rather that this is one of the many ways in which it so fails:
// This gives me one result... $should_match = ( $desired_value and ($db_value == PREF_TYPE_YES)) or (!$desired_value and ($db_value == PREF_TYPE_NO)); // ...This gives me another result. Note the identical logic. if (( $desired_value and ($db_value == PREF_TYPE_YES)) or (!$desired_value and ($db_value == PREF_TYPE_NO))) { $should_match = true; } else { $should_match = false; }
What am I missing?
Update:
David poked at this after I threw my hands up in disgust. It turns out to be a good old precedence issue, since, sensibly enough, or does not have the same precedence as ||, and similarly, and is different from &&. Therefore,
$x = true or false; // is not equivalent to $x = true || false; // but instead to ($x = true) or false; // rather than the $x = (true or false); // that I expected, and that || provides.
I see my mistake, but whoever made this design decision: I hate you.