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.
Im not talking about the symbol || and && logical operator. Im 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. The "true or false" always produces a "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, youll 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, the symbolic "||" and "&&" produces the right answer. So I would recommend you to use symbolic logical operators.
0 Comment(s)