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
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: twinge at magma dot ca
New email:
PHP Version: OS:

 

 [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: Sat Apr 27 05:01:29 2024 UTC