#50738 [Opn->Csd]: Unclear documentation in numerical string comparison
| From: | rquadling@php.net | Date: | Wed, 13 Jan 2010 13:31:48 +0000 |
| Subject: | #50738 [Opn->Csd]: Unclear documentation in numerical string comparison | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3695@lists.php.net to get a copy of this message | ||
ID: 50738
Updated by: rquadling@php.net
Reported By: I dot F dot A dot C dot Fokkema at LUMC dot nl
-Status: Open
+Status: Closed
Bug Type: Documentation problem
Operating System: All
PHP Version: Irrelevant
New Comment:
This bug has been fixed in the documentation's XML sources. Since the
online and downloadable versions of the documentation need some time
to get updated, we would like to ask you to be a bit patient.
Thank you for the report, and for helping us make our documentation
better.
Previous Comments:
------------------------------------------------------------------------
[2010-01-13 13:25:31] svn@php.net
Automatic comment from SVN on behalf of rquadling
Revision: http://svn.php.net/viewvc/?view=revision&revision=293501
Log: Fix#50738 - Type juggling is excluded from identical and not
identical comparisons.
"If you compare an integer with a string, excluding the identical (===)
and not identical (!===) operators, the string is ..."
------------------------------------------------------------------------
[2010-01-13 11:14:50] rquadling@php.net
How about ...
"If you compare an integer value with a string value (as opposed to
comparisons including type; === and !===), ..."
------------------------------------------------------------------------
[2010-01-13 11:07:06] I dot F dot A dot C dot Fokkema at LUMC dot nl
Description:
------------
Hi guys,
After someone filed bug report #23110, the documentation was greatly
improved to emphasize pitfalls when comparing numerical strings.
However, I want to suggest an addition because in my point of view it's
not clear enough.
== and === compare numerical strings differently:
echo (1 == "1e0") // Returns true, as documented
echo (1 === "1e0") // Returns false as expected, because the types are
different
echo ("1" == "1e0") // Returns true, as documented
echo ("1" === "1e0") // Returns false, but the documentation says
otherwise
The documentation at
http://www.php.net/manual/en/language.operators.comparison.php
currently
reads:
"If you compare an integer with a string, the string is converted to a
number. If you compare two numerical strings, they are compared as
integers. These rules also apply to the switch statement." - this was
added after bug report #23110. So according to this, ("1" === "1e0")
should return true; the converted numbers are equal and they're of the
same type. However, it returns false because the number conversion
described in the manual does not happen when using === or !==, but that
is not documented. More people have issues with this, as can be seen
looking through the comments on the aforementioned manual page.
Thus, I would like to suggest an addition at the end:
"(...) These rules also apply to the switch statement, but they do not
apply when using the operators === or !==, in which case there is no
type conversion used." Or a similar explanation of course.
Thank you all for your great work!
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=50738&edit=1