Today is a confusing day for 32 bit PHP

As many people probable know, there are some glaring inconsistencies between 32 bit and 64 bit PHP, especially when it comes to large numbers and floats.

For some reason, best known to the PHP developers, 32 bit PHP is limited to the maximum signed 32 bit integer size of 2147483647, while 64 bit PHP uses the 64 bit equivalent of 9223372036854775807. Many languages overcome the 32 bit / 64 bit differences by storing 64 bit ints as 2 32 bit ints to allow the usage of 64 bit integers on 32 bit systems, hence providing complete consistency between the two platforms.

These inconsistencies similarly apply to floating point precession, presumably a float in 32 bit PHP is equivalent to a 32 bit float in C, whereas it appears that in 64 bit PHP it’s actually a double.

Here is a nice example of the inconsistency, today’s unix timestamp in float form:

32 bit:

php > echo (float) 1285200000;
1.2852E+9

64 bit:

php > echo (float) 1285200000;
1285200000

This is an important thing to remember with PHP, despite the fact it is a loosely typed language, they behaviour is equivalent to the C behaviour for the particular architecture of your server.

Share

Leave a Reply