Jump to content

Weird Boolean Behavior


trevorsg

Recommended Posts

Try running the following code:

var_dump(true and !true);
$var = true and !true;
var_dump($var);

 

Was the output the same as what you expected?

 

Now try putting parentheses around the `true and !true` in the second line. The problem is fixed.

 

You can also replace `and` with `&&` and the problem is fixed as well.

 

Is this a bug in PHP? Is the `and` operator purposefully given a weaker precedence than the assignment operator?

 

Any light on this subject would be greatly appreciated. Thanks!

Link to comment
https://forums.phpfreaks.com/topic/201994-weird-boolean-behavior/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.