php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21221 [String] == 0 always true
Submitted: 2002-12-27 14:29 UTC Modified: 2002-12-27 14:35 UTC
Votes:1
Avg. Score:3.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: thebitman at attbi dot com Assigned:
Status: Wont fix Package: Feature/Change Request
PHP Version: 4CVS-2002-12-27 (stable) OS: Linux
Private report: No CVE-ID: None
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: thebitman at attbi dot com
New email:
PHP Version: OS:

 

 [2002-12-27 14:29 UTC] thebitman at attbi dot com
This is not so much a bug since it was put in intentionally, that's why I stuck this in "Feature/Change Request".
The basic problem is that ("Bob" == 0) evaluates to TRUE, defying all the logic which I've been raised with. I've tried to add this to the comments section under the documentation for bools, but after an exchange it was reccomended that I submit a Documentation Bug Report instead. I do however believe that this requires the attention of more than just documentation, so I'm submitting it here.
I've been told that the reason ("Bob" == 0) is TRUE is that "Bob" can't be translated into a numeric representation to compare to, and so it is converted to 0. By the logic of other programming languages, I would expect 0 to be converted to a string, not the other way around (I have since modified all my code to ((string)"Bob" === (string)0) ), but I dont think such being different is a bug so I'm not complaining.
The problem is that I dont consider a string that has something in it to be equal to zero. So here's what I propose: Add a new constant "BLEEM" [to borrow from George Carlin], which evaluates as being a number but does not == any number. Any string unable to be converted to a logical number, besides the empty string, will be set to BLEEM, The idea being that a string which is not a number should NEVER evaluate true when asked "Is this string equal to this number?"
This may want to be held off until a major release, since it could potentially break code.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-12-27 14:35 UTC] rasmus@php.net
This will not change.  Ad you don't need to both cast and use === at the same time.  That is overkill.  Just use ===


 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Oct 31 23:01:28 2024 UTC