Bug #77928 [Nab]: echo ('string'==0)?"TRUE":"FALSE"; // TRUE
| From: | kalle@php.net | Date: | Sun, 21 Apr 2019 15:39:07 +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-220551@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
Updated by: kalle@php.net
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:
You may also find this RFC proposal for PHP8 by Nikita relevant:
https://wiki.php.net/rfc/string_to_number_comparison
Previous Comments:
------------------------------------------------------------------------
[2019-04-21 15:37:38] kalle@php.net
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:
https://www.php.net/manual/en/language.types.type-juggling.php
https://www.php.net/manual/en/language.operators.comparison.php
If you supply the same type on both operands you will get the expected results:
https://3v4l.org/Zkind
------------------------------------------------------------------------
[2019-04-21 09:48:08] 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 09:44:10] spam2 at rhsoft dot net
what about reading a php documentation for beginners and start using === instead spam bug trackers?
------------------------------------------------------------------------
[2019-04-21 06:28:27] 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 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
------------------------------------------------------------------------
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=77928
--
Edit this bug report at https://bugs.php.net/bug.php?id=77928&edit=1