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: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: jparneodo at yahoo dot fr
New email:
PHP Version: OS:

 

 [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-2024 The PHP Group
All rights reserved.
Last updated: Tue Apr 16 22:01:27 2024 UTC