php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #786 Incorrect expression evaluation
Submitted: 1998-09-25 05:51 UTC Modified: 1998-09-25 10:07 UTC
From: torben at coastnet dot com Assigned:
Status: Closed Package: Performance problem
PHP Version: 3.0 Latest CVS OS: Linux 2.0.33 Slackware
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: torben at coastnet dot com
New email:
PHP Version: OS:

 

 [1998-09-25 05:51 UTC] torben at coastnet dot com
The following script prints "$foo == 'r'. This happens in both the module
and CGI versions. 

<?php
$foo = 0;

if ( $foo == 'r' ) {
   echo "$foo == 'r'\n";
}
?>

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [1998-09-25 10:07 UTC] zeev
When one the arguments to a comparison operator is a number,
or a string that looks like a number, the comparison is
done numerically.  In this case, 'r' is converted to a 0
(like any other non-numeric string), and thus the comparison
evaluates to TRUE.

If you know you want a string comparison, you should use
strcmp() instead.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Jan 27 12:01:24 2020 UTC