ID:               31285
 Updated by:       [EMAIL PROTECTED]
 Reported By:      geometer at ua dot fm
-Status:           Open
+Status:           Bogus
 Bug Type:         Math related
 Operating System: *
 PHP Version:      Irrelevant
 New Comment:

I can't explain why we have this, but this bug report is not meant for
those discussions (try the internals mailinglist, also I doubt it'll
get you very far). Nevertherless, there is no change that we'll ever
change this because of backward compatibility reasons.


Previous Comments:
------------------------------------------------------------------------

[2004-12-24 13:23:13] geometer at ua dot fm

Description:
------------
hello

it's not a bug, but an UNREASONABLE peculiarity of PHP (all versions).
the peculiarity may be a reason of "strange" behavior of a script and
errors may take a lot of time for their fixing.

i say about precedence of some operators. let's take a look on
precedence of bitwise operator "&" and comparison one "==".

let me need to find out is number of the lowest significant bits in $x
is less then 8 or not.
as it can be done in other programming languages, i use the following
construction:

if ($x&0x7f==$x) {ok} else {not ok}

if you try to use such a construction in a script you would be amazed,
because $x&0x7f==$x IS TRUE IF AND ONLY IF $x IS EQUAL TO 0x7f!
if you try to use 0x7f&$x==$x instead of original condition, you would
be amazed twice, because 0x7f&$x==$x IS ALWAYS TRUE.

and what the reason of this tricks? the reason is the precedence of "&"
is LOWER than one of "==".
so, i HAVE to write ($x&0x7f)==$x or (0x7f&$x)==$x, because
taking into account the precedence one obtains:

$x&0x7f==$x <=> $x&(0x7f==$x)
0x7f&$x==$x <=> 0x7f&($x==$x)

such behavior is not common in programming and in mathematics. and even
if i aware about the precedence, i can make a mistake "on the fly" in
expression (do you like to print additional parenthesis? ;)).

so, what's the reason of such particuliarly in PHP?
may be it needs to be removed from the following releases?

Reproduce code:
---------------
<?
  $x = 0x76;
  echo $x&0x7f==$x;
  echo "\n";
  echo 0x7f&$x==$x;
?>

Expected result:
----------------
1
1

Actual result:
--------------
0
1


------------------------------------------------------------------------


-- 
Edit this bug report at http://bugs.php.net/?id=31285&edit=1

Reply via email to