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
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If this is not your bug, you can add a comment by following this link.
If this is your bug, but you forgot your password, you can retrieve your password here.
Password:
Status:
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

Add a Patch

Pull Requests

Add a Pull Request

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: Tue Apr 16 13:01:30 2024 UTC