-2

demo

$code = '40001042901';
echo (int)$code; //intval($code) //same

I test on linux (Ubuntu) that result is 40001042901 but on windows result is 2147483647, what wrong with that?

XAMPP 1.8.3, PHP 5.5.15, Apache 2.4.10 (Win32)

QHu91_IT
  • 189
  • 2
  • 12

1 Answers1

2

Your Linux result is produced using 64-bit software. The Windows result comes from 32-bit software. The difference here is the maximum size of an integer, which in a 32-bit system is 2147483647.

When you try to parse the string to an integer the value is too large for a 32-bit value so PHP uses the largest available value.

In a 64-bit system integers can be much larger so PHP can use the actual value parsed from your string

  • +1 Apparently the problem still persists on windows x86_64 systems. Though [this](http://stackoverflow.com/questions/17837157) and [other](http://stackoverflow.com/questions/864058) answers point to the same somewhat [old piece of information](http://permalink.gmane.org/gmane.comp.php.devel/55886) and I'm not really sure, whether this has been fixed by now (e.g. in 5.5)... – Havelock Jun 16 '15 at 07:37