php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #10162 different behaviour of && and and operator
Submitted: 2001-04-04 11:59 UTC Modified: 2001-04-04 12:04 UTC
From: gerald dot kallas at web dot de Assigned:
Status: Closed Package: Unknown/Other Function
PHP Version: 4.0.4 OS: Windows 2000 Professional
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:
MUST BE VALID
Solve the problem:
24 - 5 = ?
Subscribe to this entry?

 
 [2001-04-04 11:59 UTC] gerald dot kallas at web dot de
in the case shown below both operators generate different values, once TRUE twice FALSE

source code

<?php
function isValid_and($a)
  {
  $valid = true;
  $b = 1;
  
  $valid = $valid and (strlen($a) >= $b);
  
  return $valid;
  }

function isValid_and_($a)
  {
  $valid = true;
  $b = 1;
  
  $valid = $valid && (strlen($a) >= $b);
  
  return $valid;
  }

$a = "";

if (isValid_and($a))
  echo "and - true<br/>";
else
  echo "and - false<br/>";

if (isValid_and_($a))
  echo "&& - true<br/>";
else
  echo "&& - false<br/>";
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-04-04 12:04 UTC] sniper@php.net
Please check this manual page:

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

Not a bug.

--Jani

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 09:01:28 2024 UTC