|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77928 echo ('string'==0)?"TRUE":"FALSE"; // TRUE
Submitted: 2019-04-20 17:59 UTC Modified: 2019-04-21 15:39 UTC
From: shamil dot kur at gmail dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.3.4 OS: Debian
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: shamil dot kur at gmail dot com
New email:
PHP Version: OS:


 [2019-04-20 17:59 UTC] shamil dot kur at gmail dot com
echo ('string'==0)?"TRUE":"FALSE"; // FALSE - OK
echo (''==0)?"TRUE":"FALSE";       // TRUE - OK
echo ('string'==1)?"TRUE":"FALSE"; // TRUE - OK
echo (''==1)?"TRUE":"FALSE";       // FALSE - OK

The actual result:
PHP 7.3.4
echo ('string'==0)?"TRUE":"FALSE"; // TRUE - it's ERROR
echo (''==0)?"TRUE":"FALSE";       // TRUE - OK
echo ('string'==1)?"TRUE":"FALSE"; // FALSE - it's ERROR
echo (''==1)?"TRUE":"FALSE";       // FALSE - OK

Test script:
if(''==0)echo       "printed text 0\n"; //this line printed
if('string'==0)echo "printed text 1\n"; //this line printed  // ERROR
if(''==1)echo       "printed text 2\n"; //never printed      
if('string'==1)echo "printed text 3\n"; //never printed      // ERROR

printed text 0
printed text 3

The actual result:
printed text 0
printed text 1


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2019-04-20 18:22 UTC] spam2 at rhsoft dot net
echo ('string'==0)?"TRUE":"FALSE"; // FALSE - OK

fix your expectations!
'string'==0 evaluates to TRUE

php > echo ('string'==0);
php > echo ('string'===0);
php >

that's how PHP works all the time
 [2019-04-20 18:53 UTC]
-Status: Open +Status: Not a bug
 [2019-04-20 18:53 UTC]
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at and the instructions on how to report
a bug at

 [2019-04-21 06:14 UTC] shamil dot kur at gmail dot com
// You are joking?
// It violates the laws of logic.
$b='string 1';
$с='string 2';

if(($a==$b) && ($a==$c))echo "\$b==\$c";

// But $b don't eq $c.
if($b!=$c)echo "\$b!=\$c";
 [2019-04-21 06:23 UTC] shamil dot kur at gmail dot com
If decided that this is not an error. That does not equate \0 to any string. Let it always be not equal. Because, it is ambiguity.
Is this logical?

if("any string"==0)echo "this\n";
if("\0"==0)echo "and this\n";

end this
 [2019-04-21 06:28 UTC] shamil dot kur at gmail dot com
Or do you want to say that when comparing with int, any string == 0? If so, then the question is closed. But "8"==8, "0"==0, "7"==7, "7"!=8 but "7"==0
 [2019-04-21 09:44 UTC] spam2 at rhsoft dot net
what about reading a php documentation for beginners and start using === instead spam bug trackers?
 [2019-04-21 09:48 UTC] spam2 at rhsoft dot net
jesus christ with == one of both needs to be implicit casted before they are compared and a lot of stuff casts to 0 but again: everybody knows that and the documentation is very clear
 [2019-04-21 15:37 UTC]
This happens due to PHP's nature of type juggling. You are supplying a string on the left operand ('string') and comparing it to an integer on the right operand (0). Please refer to the documentation for this:

If you supply the same type on both operands you will get the expected results:
 [2019-04-21 15:39 UTC]
You may also find this RFC proposal for PHP8 by Nikita relevant:
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sun Apr 11 03:01:23 2021 UTC