php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #8348 $val = TRUE AND FALSE; // Will always give TRUE !!
Submitted: 2000-12-21 06:57 UTC Modified: 2000-12-21 10:21 UTC
From: samuel dot blume at infeer dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.3pl1 OS: Linux SUSE 7.0
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: samuel dot blume at infeer dot com
New email:
PHP Version: OS:

 

 [2000-12-21 06:57 UTC] samuel dot blume at infeer dot com
Folling is unusual:

  $val = TRUE AND FALSE;  //Will always give TRUE !!
  var_dump($val);         // =  bool(false) 

using () will have the right effect 
  $val = (TRUE AND FALSE); 
  var_dump($val);         // = int(0) 

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2000-12-21 07:20 UTC] samuel dot blume at infeer dot com
Ups... a little typo above // bool(false) should be // bool(true)


$val = TRUE AND FALSE;  //Will always give TRUE !!
  var_dump($val);       // =  bool(true) 

using () or &  will have the right effect 
  $val = (TRUE AND FALSE); 
  var_dump($val);         // = int(0) 

  $val = TRUE & FALSE; 
  var_dump($val);         // = int(0) 

 [2000-12-21 10:21 UTC] stas@php.net
From Adam Trachtenberg <adam@student.net>:

You should read this page in the manual about Operator
Precedence.

http://www.php.net/manual/language.operators.precedence.php

AND has a lower precedence than =, so $val = TRUE AND FALSE
is the same as
($val = TRUE) and FALSE.

Also, you want && (logical and) instead of & (bitwise and)
in your later
example. (Although, & does have an even tighter binding than
&&, so that
"works," too.)

-adam

 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Fri Jul 04 17:01:35 2025 UTC