Bug #77928 [Nab]: echo ('string'==0)?"TRUE":"FALSE"; // TRUE
| From: | shamil dot kur at gmail dot com | Date: | Sun, 21 Apr 2019 06:28:28 +0000 |
| Subject: | Bug #77928 [Nab]: echo ('string'==0)?"TRUE":"FALSE"; // TRUE | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-220545@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=77928&edit=1
ID: 77928
User updated by: shamil dot kur at gmail dot com
Reported by: shamil dot kur at gmail dot com
Summary: echo ('string'==0)?"TRUE":"FALSE"; // TRUE
Status: Not a bug
Type: Bug
Package: *General Issues
Operating System: Debian
PHP Version: 7.3.4
Block user comment: N
Private report: N
New Comment:
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
Previous Comments:
------------------------------------------------------------------------
[2019-04-21 06:23:44] 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?
<?php
if("any string"==0)echo "this\n";
if("\0"==0)echo "and this\n";
//Result:
this
end this
------------------------------------------------------------------------
[2019-04-21 06:14:33] shamil dot kur at gmail dot com
// You are joking?
// It violates the laws of logic.
$a=0;
$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-20 18:53:02] requinix@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to
report
a bug at http://bugs.php.net/how-to-report.php
------------------------------------------------------------------------
[2019-04-20 18:22:33] spam2 at rhsoft dot net
Expected:
echo ('string'==0)?"TRUE":"FALSE"; // FALSE - OK
fix your expectations!
'string'==0 evaluates to TRUE
php > echo ('string'==0);
1
php > echo ('string'===0);
php >
that's how PHP works all the time
https://www.php.net/manual/en/language.types.type-juggling.php
------------------------------------------------------------------------
[2019-04-20 17:59:36] shamil dot kur at gmail dot com
Description:
------------
Expected:
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
Expected:
printed text 0
printed text 3
The actual result:
printed text 0
printed text 1
------------------------------------------------------------------------
--
Edit this bug report at https://bugs.php.net/bug.php?id=77928&edit=1