ID: 36799 Updated by: [EMAIL PROTECTED] Reported By: cleo at anarki dot dk Status: Bogus Bug Type: *General Issues Operating System: WinXP, Mandriva Linux 2006 PHP Version: 5.1.2 New Comment:
Nope, I don't agree. It is fully consistent with the documented precedence order. You should never use and/or over &&/|| unless you specifically want the lower precedence operator. And this is not going to change as it would break thousands of scripts out there. Previous Comments: ------------------------------------------------------------------------ [2006-03-21 19:33:09] cleo at anarki dot dk Please, I *am* using the bug system to report a rather hideous bug. You mention an example, where = needs to have higher precedence than or: $foo = query() or die(); Now, this is a smart hack one can use in the absence of proper error handling, like exception handling. But it is a hack, and it messes up semantics: It says that if query() is false, then $foo should be assigned the value of die(). But this is not what happens because of how die() works. It is, in my opinion, not an argument strong enough to overpower the hideous error that: $test= true and false; evaluates to true. Don't you agree with me, that this is unfortunate, to say the least? Regards Claus Holm, Copenhagen, Denmark ------------------------------------------------------------------------ [2006-03-21 10:11:20] [EMAIL PROTECTED] 'and' and 'or' have the same precedence level. $foo = query() or die(); You need the = to be higher precedence here. Also, please don't use our bug system as a support forum. ------------------------------------------------------------------------ [2006-03-21 09:18:02] cleo at anarki dot dk Thanks Rasmus, At last someone comes up with an explanation. I can see the point of having to versions of boolean and, each with different precedence. However, the precedence of 'and' should definitely not be lower than '='. What is your argument? I mean: $test= true and false; echo $test ? "ok" : "nope"; I am sorry, but it can never be correct to let $test evaluate to true here!!! As I see it, PHP does the following: ($test= true) and false So, $test will be set to true, and the assignment will be true, and that assignment will be and'ed with false, and the result is discarded. But who would want that? Conclusion: $test1= true and false; // Evaluates to true $test2= true && false; // Evaluates to false '=' and 'and' have wrong precedences in PHP. One should always use && instead of 'and', as && used in an assignment statement gives the results you would expect from boolean algebra. And 'and' does not. Best regards, and the hope of recognition of my arguments Claus Holm, Copenhagen, Denmark. ------------------------------------------------------------------------ [2006-03-21 01:59:51] [EMAIL PROTECTED] The whole point of 'and','or' is to be the low-precedence version of '&&', '||'. If you want high-precedence, use &&. ------------------------------------------------------------------------ [2006-03-20 20:05:03] [EMAIL PROTECTED] http://www.php.net/manual/en/language.operators.php#language.operators.precedence ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at http://bugs.php.net/36799 -- Edit this bug report at http://bugs.php.net/?id=36799&edit=1