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

I ran into a problem in my code when switching to production, because the production server is 32 bit and my development machine is 64 bit (I am running Kubuntu 12.04 64 bit). My question is. Is it possible to force int 32 bits without installing a 23 bit version of PHP? Either this, or a library that allows me to select the value of max int

+4
source share
1 answer

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

Note that when overflowing integer operations, variables become float. The PHP documentation explains it all well.

I'm not sure what you are doing in your code so that you take care of what size an integer is. However, if you only care about 32-bit values, you can always mask low 32 bits:

$val = $something & 0xFFFFFFFF; 
+8
source

All Articles