php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #53360 wrong operator precedence
Submitted: 2010-11-19 18:53 UTC Modified: 2010-11-19 21:52 UTC
From: torkvemada at nigma dot ru Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: Irrelevant OS: any
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: torkvemada at nigma dot ru
New email:
PHP Version: OS:

 

 [2010-11-19 18:53 UTC] torkvemada at nigma dot ru
Description:
------------
According to documentation, comparison operators (like ==) have higher priority than bitwise ones (like &). 
However, the ==operator has higher precedence than &.

It was tested on Debian Squeeze (PHP 5.3.2-1 with Suhosin-Patch) and Debian Lenny (PHP 5.2.6-1+lenny9 with Suhosin-Patch 0.9.6.2).


Test script:
---------------
$flag = 1;
var_dump($flag & 3 == 1);
var_dump(($flag & 3) == 1);

Expected result:
----------------
bool(true)
bool(true)

Actual result:
--------------
int(0)
bool(true)

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2010-11-19 19:42 UTC] sixd@php.net
-Status: Open +Status: Bogus
 [2010-11-19 19:42 UTC] sixd@php.net
Higher precedence implies "tighter binding", so 
var_dump($flag & 3 == 1);
is the same as
var_dump($flag & (3 == 1));
Both of these return
int(0)
 [2010-11-19 21:52 UTC] torkvemada at nigma dot ru
Ah, sorry, I've read the docs not very careful :(
Ticket should be closed.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 13:01:33 2025 UTC