php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25763 Why the string "1.10" is equal to the string "1.1"?
Submitted: 2003-10-06 14:08 UTC Modified: 2003-10-06 14:18 UTC
From: jparneodo at yahoo dot fr Assigned:
Status: Wont fix Package: Strings related
PHP Version: 4.3.3 OS: RH7.2
Private report: No CVE-ID:
Have you experienced this issue?
Rate the importance of this bug to you:

 [2003-10-06 14:08 UTC] jparneodo at yahoo dot fr
Description:
------------
I excepted true if one of the compared variable was numeric,
because of type juggling rules (Appendix K. PHP type comparison tables), but false when the 2 
variables are string.
In this case == and === must have the same result.

Reproduce code:
---------------
$a=(string)"1.1";
$b=(string)"1.10";
if($a==$b) echo "equal";
else echo "different";


Expected result:
----------------
different

Actual result:
--------------
equal

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-10-06 14:18 UTC] pollita@php.net
Answer: Because PHP is a loose-typed lanague.

== will evaluate to TRUE if the two values CAN be shown to be equal within reason.

Calling 1.1 equal to 1.10 is within reason.

You clearly know about the === comparison type so I won't bother pointing that out.
 
PHP Copyright © 2001-2017 The PHP Group
All rights reserved.
Last updated: Fri Mar 24 20:01:40 2017 UTC