php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #47795 Strange String Comparison
Submitted: 2009-03-26 21:16 UTC Modified: 2009-03-26 22:27 UTC
From: bphelan at paycomonline dot com Assigned:
Status: Wont fix Package: Strings related
PHP Version: 5.3.0RC1 OS: Windows XP
Private report: No CVE-ID: None
 [2009-03-26 21:16 UTC] bphelan at paycomonline dot com
Description:
------------
Whenever you compare strings of the format "1D-XXXX" where XXXX is any number between 4950 and 5201, they will always return true. For example "1D-5155" == "1D-5200" will return true.

We are running an old version of PHP (4.3.6) but I haven't found any instance where this bug was encountered. If this error has already been corrected, if someone could let me know which version it was fixed, I'd appreciate it.

Reproduce code:
---------------
for($i = 4950; $i <= 5201; $i++){
	$compareInt = "1D-$i";
	
	if($compareInt == "1D-5155"){
		echo "$compareInt == 1D-5155<BR>";
	}
	else{
		echo "$compareInt != 1D-5155<BR>";
	}
}

Expected result:
----------------
I've generated a simple for loop that goes through all of the values in the range. One would expect that only one instance would be correct, namely the case where $compareInt is "1D-5155"

Actual result:
--------------
If you take a look at the code you will see the listing of which values are considered equal and which are not. For some reason all strings within the range of 4950 to 5201 are considered equal if they are compared against each other. All other strings outside of the range appear to be compared as expected.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-03-26 22:27 UTC] scottmac@php.net
We are sorry, but we can not support PHP 4 related problems anymore.
Momentum is gathering for PHP 6, and we think supporting PHP 4 will
lead to a waste of resources which we want to put into getting PHP 6
ready.

We only take bug reports against the latest versions, if you want to look at where something is fixed then look at the changelog.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Sat Dec 21 14:01:32 2024 UTC