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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 23:01:28 2024 UTC