Edit report at https://bugs.php.net/bug.php?id=64324&edit=1
ID: 64324 Updated by: ras...@php.net Reported by: dosergio at ig dot com dot br Summary: Why 0 == 'BOOK' ? Status: Not a bug Type: Bug Package: *General Issues Operating System: all PHP Version: Irrelevant Block user comment: N Private report: N New Comment: So by your logic 12=='13' Do you have any idea how much code that would break? The web is not typed. Everything comes across as strings. And everyone does stuff like if($_GET['age']==19) { ... } which you are proposing to break. Same goes for data retrieved from databases. Everything comes back as strings. So no, this is simply not going to happen. Please stop. Previous Comments: ------------------------------------------------------------------------ [2013-03-02 01:46:02] dosergio at ig dot com dot br 12 == 'TEXT' in the "boolean" point of view is correct. Javascript agrees with it. ------------------------------------------------------------------------ [2013-03-02 01:40:32] ras...@php.net No it doesn't make more sense. This would make 12=='TEST' You cast to a type in the comparison, not to some third type. Besides changing this would break millions of lines of code. Not going to happen. ------------------------------------------------------------------------ [2013-03-02 01:19:42] dosergio at ig dot com dot br A good rule to be implemented by PHP is: If a comparison of simple equality ( == ) or simple inequality ( != ) is done between two different data types, PHP should cast both to boolean before comparing. Because 'TEXT' casts to true, 0 casts to false so 0 != 'TEXT' makes more sense than 0 == 'TEXT'. ------------------------------------------------------------------------ [2013-02-28 19:12:25] dosergio at ig dot com dot br OK, you are right. That was the explanation I wanted: it depends on the type you compare. if( false == 'TEST') works correctly. Now it makes a little more sense to me. But javascript is still superior because inside a if() I suspect that any language should try to cast both to boolean. ------------------------------------------------------------------------ [2013-02-28 19:04:24] ras...@php.net We don't want a special case for 0. By your logic 12 == 'TEST' should be true. You are assuming a cast to boolean even though neither side of the comparison is a boolean. Note that true == 'TEST' will match because here we cast to boolean. But 'TEST' cast to an integer is going to give you 0. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=64324 -- Edit this bug report at https://bugs.php.net/bug.php?id=64324&edit=1