php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #43964 Comparison of strings containing numbers results in an incorrect response.
Submitted: 2008-01-29 09:25 UTC Modified: 2008-01-29 10:09 UTC
From: twinge at magma dot ca Assigned:
Status: Not a bug Package: Strings related
PHP Version: 5.2.5 OS: openSuse 10.3
Private report: No CVE-ID: None
 [2008-01-29 09:25 UTC] twinge at magma dot ca
Description:
------------
If two strings containing numbers are compared using an if statement, only the first 16 bytes of the string are compared. Any bytes after the 16th byte are ignored in the comparison.

Reproduce code:
---------------
<?PHP

$value1="12345678901234567890123456789012";
$value2="12345678901234567890123456789011";

if ($value1!=$value2){print"Not equal.<br>";}
if ($value1==$value2){print"Equal.<br>";}

var_dump($value1);
print "<br>";
var_dump($value2);
print "<br>";

?>

Expected result:
----------------
Not equal.
string(32) "12345678901234567890123456789012" 
string(32) "12345678901234567890123456789011" 


Actual result:
--------------
Equal.
string(32) "12345678901234567890123456789012" 
string(32) "12345678901234567890123456789011" 


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-01-29 10:09 UTC] felipe@php.net
This is expected, PHP converts numerical string to type integer/float.

var_dump((int) "12345678901234567890123456789012");
var_dump((int) "12345678901234567890123456789011");

int(2147483647)
int(2147483647)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Feb 29 19:01:30 2024 UTC