Doc #80502 [Com]: Comparison of empty string to 0
| From: | kimia dot saladdmo9881 at gmail dot com | Date: | Wed, 25 Jan 2023 09:22:26 +0000 |
| Subject: | Doc #80502 [Com]: Comparison of empty string to 0 | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-19566@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=80502&edit=1
ID: 80502
Comment by: kimia dot saladdmo9881 at gmail dot com
Reported by: craig at craigfrancis dot co dot uk
Summary: Comparison of empty string to 0
Status: Verified
Type: Documentation Problem
Package: *General Issues
Operating System: N/A
PHP Version: 8.0.0
Block user comment: N
Private report: N
New Comment:
That was so great.
(https://www.fmc4me.net/)github.com
Previous Comments:
------------------------------------------------------------------------
[2022-11-04 02:46:31] php dot net at sameprecision dot org
Why not stick with the most prolific scripting language on earth, javascript? 0 == ""
------------------------------------------------------------------------
[2022-11-04 02:25:50] php dot net at sameprecision dot org
Indeed this is causing problems and breaks compatibility with javascript where 0 == "".
With PHP 8, 0 != "".
What RFC is being referenced with this? Why would coercion to string "0" make sense here
to have "0" != "" instead of false == false or 0 == 0?
------------------------------------------------------------------------
[2020-12-10 14:21:19] craig at craigfrancis dot co dot uk
https://www.php.net/manual/en/language.operators.comparison.php
Operand 1: string, resource, int or float
Operand 2: string, resource, int or float
Result: Translate strings and resources to numbers, usual math
I have a horrible feeling this change is going to cause issues, as PHP is typically working with
user input from web forms, where the GET/POST values provided are strings, same with many other
sources (e.g. fgetcsv).
------------------------------------------------------------------------
[2020-12-10 12:49:08] cmb@php.net
Yes, that is indeed a consequence of that RFC. Since the empty
string is not a well-formed numeric string, a string comparison is
done, and the empty string is less than any other string. The
migration guide should not only mention == comparision, but the
other affected operations as well. And of course the respective
documentation in the manual proper needs to be updated.
------------------------------------------------------------------------
[2020-12-10 12:27:28] craig at craigfrancis dot co dot uk
And the same with ('' == 0)... PHP 7 this would be true, PHP 8 it's false.
While I appreciate that's supposed to be false with ('' === 0), the double equals
comparison operator is supposed to be equal "after type juggling".
------------------------------------------------------------------------
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=80502
--
Edit this bug report at https://bugs.php.net/bug.php?id=80502&edit=1