Max int value?

I have a problem with int values.

$ticketId=7135306757429060445;
echo $ticketId gives me 7.1353067574291E+18

Why that, is there any max allowed size for int or what is the problem? So do I need to put larger int as a string?

http://www.php.net/manual/en/language.types.integer.php

I read this but since I am quite new into php and I don’t understand this documentation entirely and I don’t know what could be a solution in this case.

As I understand the problem is that the integer is too large. I use facebook api where user ids and albums ids get so large. So is the solution to use it as string instead of integer?

not necessarily

your example number 7135306757429060445 still fits within the range of numbers for BIGINT, which goes up to 9223372036854775807

It all depends if your host is 32bit or 64bit. A 32bit system can process an Int from -2147483648 to +2147483648, whereas a 64bit one −9223372036854775807 to +9223372036854775807.

Sure, store the value in your database as a 64bit Int, but if you have a 32bit host you’ll need to typecast it to a string to work with it.

You can check the following, pre-defined, constants for clarity. :slight_smile:

32bit


var_dump(
  PHP_INT_MAX
); # int(2147483647)

var_dump(
  PHP_INT_SIZE
); # int(4) 

64bit


var_dump(
  PHP_INT_MAX
); # int(9223372036854775807)

var_dump(
  PHP_INT_SIZE
); # int(8) 

*Disclaimer: I maybe completely wrong. :stuck_out_tongue:

Yes, use strings and if you need to do any calculations you can use BCMath functions.