trevorsg Posted May 17, 2010 Share Posted May 17, 2010 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 More sharing options...
PFMaBiSmAd Posted May 17, 2010 Share Posted May 17, 2010 http://us3.php.net/manual/en/language.operators.precedence.php Link to comment https://forums.phpfreaks.com/topic/201994-weird-boolean-behavior/#findComment-1059280 Share on other sites More sharing options...
trevorsg Posted May 17, 2010 Author Share Posted May 17, 2010 Ah, I was just looking for that part of the manual, and I couldn't find it. What is the reasoning behind this? Ooh, I just had a thought - it's that way so you can do something like $blah = doSomething() or die("Can't do something"); Ok, makes sense now. Link to comment https://forums.phpfreaks.com/topic/201994-weird-boolean-behavior/#findComment-1059281 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.