Importing from 32bit PHP via JSON

This is a short one. Basically if you need to deal with timestamps, beware. The value of a timestamp in microtime (the thing that JavaScript uses) is larger than the maximum integer a 32bit PHP installation can produce.

JS microtime:               1392804671000
PHP max int on 32bit:          2147483647
PHP max int on 64bit: 9223372036854775807

I mean you can do it, but then your JavaScript importer needs to take the value as a string as well. One more thing, sprintf( '%u', $number ); will give you a string.


”The JavaScript date is based on a time value that is milliseconds since midnight 01 January, 1970 UTC. A day holds 86,400,000 milliseconds. The JavaScript Date object range is -100,000,000 days to 100,000,000 days relative to 01 January, 1970 UTC.“ MDN Docs on Date

”The size of an integer is platform-dependent, although a maximum value of about two billion is the usual value (that's 32 bits signed). 64-bit platforms usually have a maximum value of about 9E18. PHP does not support unsigned integers.“ PHP Docs on Integer

”32-bit builds of PHP: from -2147483648 to 2147483647. 64-bit builds of PHP: from -9223372036854775808 to 9223372036854775807“ Obligatory SO answer