Edit report at https://bugs.php.net/bug.php?id=63861&edit=1
ID: 63861 Updated by: ni...@php.net Reported by: rstoll at tutteli dot ch Summary: weak logic operator are buggy -Status: Open +Status: Not a bug Type: Bug Package: Scripting Engine problem PHP Version: 5.4.10 Block user comment: N Private report: N New Comment: The OR, XOR, AND operators are special variants of the usual logic operator with different precedence. In particular they have lower precedence than '='. That's why all your assignments are interpreted like this: ($a = false) or true; Instead you should be using the normal && and || operators, those will be correctly interpreted as $a = (false || true); The reason we have the lower-precedence variants is to allow things like $result = mysql_query(...) or die(mysql_error()); This is obviously a very bad example, but probably also the one most used. It basically allows you to combine an assignment with an error check. This behavior is consistent with other languages that implement both the normal || and && operators as well as the OR and AND operators. Previous Comments: ------------------------------------------------------------------------ [2012-12-27 10:37:13] rstoll at tutteli dot ch Description: ------------ see test script. Seems like the weak logic operators do not have any effect. My PHP version is 5.4.7 Was already mentioned in https://bugs.php.net/bug.php?id=46530&edit=2 Test script: --------------- $a = false or true; var_dump($a); //boolean false $a = true or false; var_dump($a); //boolean true - that's ok $a = true xor true; var_dump($a); //boolean true $a = false xor true; var_dump($a); //boolean false $a = true and false; var_dump($a); //boolean true Expected result: ---------------- //or boolean true boolean true - this one worked as expected //xor boolean false boolean true //and boolean false ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=63861&edit=1