php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #31380 PHP logic problem
Submitted: 2005-01-02 23:28 UTC Modified: 2005-01-02 23:37 UTC
From: alex at arjomand dot net Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 4.3.10 OS: Windows XP Pro
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: alex at arjomand dot net
New email:
PHP Version: OS:

 

 [2005-01-02 23:28 UTC] alex at arjomand dot net
Description:
------------
There is a problem with PHP's logic and string conventions. Currently, the comparison 0 == "alex" (or any arbitrary string) returns true. The comparison 0 == false also returns true, but the comparison "alex" == false returns false. This gives us the following logical fallacy:
   A == B,
   B == C,
   but A != C.

The first comparison (0 == 'alex') is due to a PHP convention explained here: http://ca.php.net/manual/en/language.types.string.php#language.types.string.conversion

The third comparison ("alex" == false) is due to an implicit PHP convention - that any non-empty string is true.

These two conventions are inconsistent, and lead to the above errors. Under this system, PHP no longer has referential integrity.

Reproduce code:
---------------
<?
   echo (0 == false) === true;        # returns true
   echo "<br>";
   echo (0 == "alex") === true;       # returns true
   echo "<br>";
   echo ("alex" == false) === false;  # returns false
?>


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-01-02 23:30 UTC] alex at arjomand dot net
Sorry, that last line in the Reproduce code should read:

   echo ("alex" == false) === false;  # returns TRUE
 [2005-01-02 23:37 UTC] rasmus@php.net
This is by design and won't change.  
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Thu Jul 17 14:04:04 2025 UTC