php.net |  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
View Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
If you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: aaz at althenia dot net
New email:
PHP Version: OS:

 

 [2011-02-02 13:51 UTC] 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.


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-02-10 12:44 UTC] 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-10 12:47 UTC] vrana@php.net
-Status: Open +Status: Closed -Assigned To: +Assigned To: vrana
 [2011-02-10 12:47 UTC] vrana@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.

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-2024 The PHP Group
All rights reserved.
Last updated: Sun Dec 22 08:01:29 2024 UTC