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
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Sun May 19 15:01:31 2024 UTC