Doc #53908 [Opn->Csd]: String comparison by == and ===
| From: | vrana@php.net | Date: | Thu, 10 Feb 2011 11:47:03 +0000 |
| Subject: | Doc #53908 [Opn->Csd]: String comparison by == and === | ||
| References: | 1 | Groups: | php.doc.bugs |
| Request: | Send a blank email to doc-bugs+get-5942@lists.php.net to get a copy of this message | ||
Edit report at http://bugs.php.net/bug.php?id=53908&edit=1
ID: 53908
Updated by: vrana@php.net
Reported by: aaz at althenia dot net
Summary: String comparison by == and ===
-Status: Open
+Status: Closed
Type: Documentation Problem
Package: Documentation problem
PHP Version: 5.3.5
-Assigned To:
+Assigned To: vrana
Block user comment: N
Private report: N
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.
Changed to "$a is equal to $b after type juggling".
There has already been this statement right behind the table: "If ...
the comparison involves numerical strings, then each string is converted
to a number". And there's also the table Comparison with Various Types.
Previous Comments:
------------------------------------------------------------------------
[2011-02-10 12:44:46] vrana@php.net
Automatic comment from SVN on behalf of vrana
Revision: http://svn.php.net/viewvc/?view=revision&revision=308181
Log: Equals after type juggling (doc bug #53908)
------------------------------------------------------------------------
[2011-02-02 13:51:25] aaz at althenia dot net
Description:
------------
Currently http://www.php.net/manual/en/language.operators.comparison.php
says in
the table:
$a == $b Equal TRUE if $a is equal to $b.
$a === $b Identical TRUE if $a is equal to $b, and they are
of the same type. (introduced in PHP 4)
This is confusing because "1.2" == "1.20" (so "$a is equal to $b"),
and
they are
of the same type, but "1.2" !== "1.20". In other words, the type
comparison is
not the only difference between == and ===, as implied by this table.
I suggest rewording this to something like:
$a === $b Identical TRUE if $a is identical in type and value to
$b.
Below it also says
The type conversion does not take place when the comparison is === or
!== as
this involves comparing the type as well as the value.
The was added due to bug 50738. However, the "as this involves" part is
not
important here, but again implies that the type comparison is the only
difference, so I suggest removing it.
A section dealing specifically with the smart string comparison would be
very
helpful, especially since it is different from normal string-to-number
conversion ("5z" == 5 while "5z" != "5"). This could even be a
separate
page
(like http://www.php.net/manual/en/language.oop5.object-comparison.php
for
objects, which is linked from the second table).
Examples can come from past bugs:
bug 1974, bug 23110, bug 25763, bug 25943, bug 39084, bug 43304.
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/bug.php?id=53908&edit=1