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

Pull Requests

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-2025 The PHP Group
All rights reserved.
Last updated: Sun Jan 05 09:01:27 2025 UTC