|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26122 Logical Operator "and" not functioning as expected
Submitted: 2003-11-04 16:00 UTC Modified: 2003-11-04 16:08 UTC
From: iam at nimajneb dot com Assigned:
Status: Not a bug Package: Math related
PHP Version: 4.3.2 OS: Mac OSX 10.2.6
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
Solve the problem:
17 + 22 = ?
Subscribe to this entry?

 [2003-11-04 16:00 UTC] iam at nimajneb dot com
Result of 'and' operator not what is expected. 1 and 0 and 1 => 1? Should be 0. See attached code sample. '&&' operator does function correctly however.

Reproduce code:
    $primary_err_valid = (($_POST['primary_err'] != "category") and ($_POST['primary_err'] != "separator"));
    $secondary_err_valid = (($_POST['secondary_err'] != "category") and ($_POST['secondary_err'] != "separator"));
    $tertiary_err_valid = (($_POST['tertiary_err'] != "category") and ($_POST['tertiary_err'] != "separator"));
    $error_valid = ($primary_err_valid) and ($secondary_err_valid) and ($tertiary_err_valid);

	echo "Pri: $primary_err_valid <br>";
	echo "Sec: $secondary_err_valid <br>";
	echo "Tri: $tertiary_err_valid <br>";
	echo "Total Error: $error_valid <br>";

Expected result:
Pri: 1
Tri: 1
Total Error: 

Actual result:
Pri: 1
Tri: 1
Total Error: 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-11-04 16:08 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

'and' is equivalent to &, which is a bitwise operator. && is something else entirely.
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Jun 19 04:01:31 2024 UTC