Today, When I was doing some programming stuffs and I found out that there is serious flaw in the “and” , “or” logical operator of PHP. I’m not talking about the symbol “||” and “&&” logical operator. I’m talking about the “and” and “or” logical operator (operator with words).
Example of the flaw of using “and” and “or” logical operator
Look at the following example and notice the output of this example,
$return_val = false or true; var_dump($return_val); //prints bool(false) $return_val = true and false; var_dump($return_val); //prints bool(true)
As you can see in the first example, “bool(false)” is the output in the browser. I don’t need to tell you that “false or true” is always true and there is no doubt about this. But look at the output, what a freaking output by the “or” operator of PHP.
And now, just look at the second example, you’ll see “bool(true)” as a output to the browser. What a ridiculous result? How can “true and false” can be true, it must be “false” without any doubt.
But, you’ll not get such a kind of rediculous result with “||” and “&&” logical operator.