|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Doc Bug #53908 String comparison by == and ===
Submitted: 2011-02-02 13:51 UTC Modified: 2011-02-10 12:47 UTC
From: aaz at althenia dot net Assigned: vrana (profile)
Status: Closed Package: Documentation problem
PHP Version: 5.3.5 OS:
Private report: No CVE-ID: None
 [2011-02-02 13:51 UTC] aaz at althenia dot net
Currently 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 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.


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-10 12:44 UTC]
Automatic comment from SVN on behalf of vrana
Log: Equals after type juggling (doc bug #53908)
 [2011-02-10 12:47 UTC]
-Status: Open +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 12:47 UTC]
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.
PHP Copyright © 2001-2023 The PHP Group
All rights reserved.
Last updated: Mon Dec 11 03:01:27 2023 UTC