Skip to content
Advertisement

How to use a 32bit integer on a 64bit installation of PHP?

I run into a problem on my code when moved to production because the production server is 32bit while my development machine is 64bit (I’m running Kubuntu 12.04 64bit). My question is. Is it possible to force an int to be 32bit without installing the 23bit version of PHP? Either that or a library that allow me to chose the max int value

Advertisement

Answer

Integers are the size of pointers on that platform. (32-bit PHP –> 32-bit integers. 64-bit PHP –> 64-bit integers).

Note that when integer operations overflow, the variables become floats. The PHP documentation explains all of this well.

I’m not sure what you’re doing in your code that would cause you to care what size the integer is though. If you only care about 32-bits of a value, however, you can always mask off the low 32 bits:

$val = $something & 0xFFFFFFFF;
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement