« LDAP performance is poor.. | Home | Migrating from blogspot to Movable Type »

December 1, 2011

PHP and big numbers

One would expect, that one of the most used script languages of the world would be ableto do proper comparisons of numbers, even big numbers, right?Well, PHP is not such a language, at least not on 32bit systems.Given a script like this:

$t1 = "1244431010010381771";
$t2 = "1244431010010381772";
if ($t1 == $t2) {
    print "equal\n";

A current PHP version will output:

schoenfeld@homer ~ % php5 test.php

It will do the right thing on 64bit systems (not claiming that the numbers are equal).Interesting enough: An equal-type-equality check (see my article from a few years ago) will not tell that the two numbers are equal.


That's crazy. Those are strings.

Well, no, not really. As the string does not store anything except numbers PHP will coerce it into a numeric data type, which makes perfect sense due to the nature of the PHP type handling.

Leave a comment