#50738 [Csd]: Unclear documentation in numerical string comparison
| From: | I dot F dot A dot C dot Fokkema at LUMC dot nl | Date: | Wed, 13 Jan 2010 15:08:22 +0000 |
| Subject: | #50738 [Csd]: Unclear documentation in numerical string comparison | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-3699@lists.php.net to get a copy of this message | ||
ID: 50738
User updated by: I dot F dot A dot C dot Fokkema at LUMC dot nl
Reported By: I dot F dot A dot C dot Fokkema at LUMC dot nl
Status: Closed
Bug Type: Documentation problem
Operating System: All
PHP Version: Irrelevant
New Comment:
Almost... :) Now it doesn't include anymore that if one is a normal
string and the other is a number (int/float) that the string will be
converted.
Because ('a' == 0 && 'a' == 0.0) !
Keeping the first sentence (although changing int=>number) and add it
to your new text should suffice, don't you think? So how about:
"If you compare a number with a string, the string is converted to a
number. If a comparison involves numerical strings, then each string in
the comparison is converted to a number and then the comparison is
performed numerically. The type conversion does not take place when
the comparison is === or !== as these involve comparing the type as
well as the value. These rules also apply to the switch statement."
Previous Comments:
------------------------------------------------------------------------
[2010-01-13 14:49:03] rquadling@php.net
Also, 2 strings are NOT compared as "integers" ...
php -r "var_dump('123.4'=='1.234e2');"
outputs
bool(true)
So ...
"If a comparison involves numerical strings, then each string in the
comparison is converted to a number and then the comparison is
performed numerically. The type conversion does not take place when
the comparison is === or !== as these involve comparing the type as
well as the value. These rules also apply to the switch statement."
I think covers it all and the correction with the word "integers".
------------------------------------------------------------------------
[2010-01-13 13:53:42] I dot F dot A dot C dot Fokkema at LUMC dot nl
I hope I'm not bothering you too much now, but do you think people will
understand the conversion also doesn't take place when comparing two
numerical strings? Now it seems to me it's affecting only the
integer-to-string comparison...
By the way, !=== needs to be !== :)
------------------------------------------------------------------------
[2010-01-13 13:31:48] rquadling@php.net
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.
------------------------------------------------------------------------
[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 !===), ..."
------------------------------------------------------------------------
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
http://bugs.php.net/50738
--
Edit this bug report at http://bugs.php.net/?id=50738&edit=1