php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30689 logical operators not working as expected
Submitted: 2004-11-04 18:54 UTC Modified: 2004-11-16 06:52 UTC
From: ioan dot nicu at ines dot ro Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4CVS-2004-11-04 (stable) OS: Linux
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: ioan dot nicu at ines dot ro
New email:
PHP Version: OS:

 

 [2004-11-04 18:54 UTC] ioan dot nicu at ines dot ro
Description:
------------
The logical operators 'and', 'or', 'xor' have unexpected
results. The bug doesn't occur when using C-style logical
operators ( ||, &&, ^^).

From the php manual (Logical Operators Section):
http://www.php.net/manual/en/language.operators.logical.php

Example   | Name | Result
--------------------------------------------------
$a and $b | And  | TRUE if both $a and $b are TRUE.
$a or $b  | Or	 | TRUE if either $a or $b is TRUE.
$a xor $b | Xor	 | TRUE if either $a or $b is TRUE, but not both.


This bug is reproducible on the latest stable snapshot from
cvs.


Reproduce code:
---------------
<?
$a1 = false or true; $a2 = true or false;
$b1 = true or false; $b2 = false and true;
$c = true xor true; 

echo("false or true = ");var_dump($a1);
echo("true or false = ");var_dump($a2);
echo("true and false = ");var_dump($b1);
echo("false and true = ");var_dump($b2);
echo("true xor true = ");var_dump($c);

?>

Expected result:
----------------
false or true = bool(true)
true or false = bool(true)
true and false = bool(false)
false and true = bool(false)
true xor true = bool(false)

Actual result:
--------------
false or true = bool(false)
true or false = bool(true)
true and false = bool(true)
false and true = bool(false)
true xor true = bool(true)


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-04 20:58 UTC] derick@php.net
No bug here, the = operator has a higher precedence than and, or and xor so you'll have to use parenthesis. See: http://www.php.net/manual/en/language.operators.php#language.operators.precedence
 [2004-11-16 00:22 UTC] ioan dot nicu at ines dot ro
Sorry, you are right.
I'm closing this bug report.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Sep 19 14:01:28 2024 UTC