#22736 [Opn->Bgs]: change of operator precedence
ID: 22736
Updated by: mgf@php.net
Reported By: soletan at toxa dot de
-Status: Open
+Status: Bogus
Bug Type: Feature/Change Request
Operating System: Linux
PHP Version: 4.3.1
New Comment:
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
I think your precedence information seems to be a little awry.
According to the manual page at
http://www.php.net/manual/en/language.operators.php,
~ has greater
priority than != has greater priority than &, ^, | (in that order).
This means that your example of
$a & ~$b != 0
actually equates to
$a & ((~$b) != 0)
(and I've just tested this, so I'm sure it's right.) This isn't nearly
as bad as you suggest (but, I agree, a little unexpected -- until I
checked, I'd have expected &, ^, | to be higher-precedence than ==, !=
etc!).
So, your example of ~p ^ q *will* be evaluated as (~p) ^ q, and,
indeed, any expression containing solely bitwise operators will
function as expected -- only if you add comparison operators into the
mix will you have to be careful to add parentheses to get the required
result.
Previous Comments:
------------------------------------------------------------------------
[2003-03-16 07:28:38] soletan at toxa dot de
Hi,
maybe this can't be done because of scripts relying on current operator
precedence, but for the statement
$a & ~$b != 0
your current precedence rules would do
$a & ~( $b != 0 )
which is quite unusual. Traditional logics (used by Frege and others)
would first compute the negation, it is the most strongly bound
operator. For instance, having
~p ^ q
as a structured expression the negation would precede any other
operator p is argument of, or: p is not argument of the conjunction,
but the negation's result is.
Maybe I'm still false, but that's what I have expected to write logical
calculations like for years.
Best Regards,
Thomas Urban
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=22736&edit=1
Thread (3 messages)