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
 [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: Wed Aug 12 10:01:25 2020 UTC