Doc #53908 [NEW]: String comparison by == and ===
| From: | aaz at althenia dot net | Date: | Wed, 02 Feb 2011 12:51:25 +0000 |
| Subject: | Doc #53908 [NEW]: String comparison by == and === | ||
| Groups: | php.doc.bugs | ||
| Request: | Send a blank email to doc-bugs+get-5907@lists.php.net to get a copy of this message | ||
From:
Operating system:
PHP version: 5.3.5
Package: Documentation problem
Bug Type: Documentation Problem
Bug description:String comparison by == and ===
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 bug report at http://bugs.php.net/bug.php?id=53908&edit=1
--
Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=53908&r=trysnapshot52
Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=53908&r=trysnapshot53
Try a snapshot (trunk): http://bugs.php.net/fix.php?id=53908&r=trysnapshottrunk
Fixed in SVN: http://bugs.php.net/fix.php?id=53908&r=fixed
Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=53908&r=needdocs
Fixed in release: http://bugs.php.net/fix.php?id=53908&r=alreadyfixed
Need backtrace: http://bugs.php.net/fix.php?id=53908&r=needtrace
Need Reproduce Script: http://bugs.php.net/fix.php?id=53908&r=needscript
Try newer version: http://bugs.php.net/fix.php?id=53908&r=oldversion
Not developer issue: http://bugs.php.net/fix.php?id=53908&r=support
Expected behavior: http://bugs.php.net/fix.php?id=53908&r=notwrong
Not enough info: http://bugs.php.net/fix.php?id=53908&r=notenoughinfo
Submitted twice: http://bugs.php.net/fix.php?id=53908&r=submittedtwice
register_globals: http://bugs.php.net/fix.php?id=53908&r=globals
PHP 4 support discontinued: http://bugs.php.net/fix.php?id=53908&r=php4
Daylight Savings: http://bugs.php.net/fix.php?id=53908&r=dst
IIS Stability: http://bugs.php.net/fix.php?id=53908&r=isapi
Install GNU Sed: http://bugs.php.net/fix.php?id=53908&r=gnused
Floating point limitations: http://bugs.php.net/fix.php?id=53908&r=float
No Zend Extensions: http://bugs.php.net/fix.php?id=53908&r=nozend
MySQL Configuration Error: http://bugs.php.net/fix.php?id=53908&r=mysqlcfg